cache

package
v0.27.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package cache is a pluggable key/value cache abstraction. The default backend is process-local in-memory (no external service), with an opt-in Redis backend for a distributed cache. Redis tests run against an in-process miniredis, so no server is required for the default suite.

Index

Constants

This section is empty.

Variables

View Source
var ErrCacheMiss = apperr.New(apperr.CatNotFound, "cache miss")

ErrCacheMiss is returned by Get when the key is absent.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(ctx context.Context, key string) ([]byte, error)
	Set(ctx context.Context, key string, val []byte, ttl time.Duration) error
	Del(ctx context.Context, key string) error
	Close() error
}

Cache is a minimal byte-oriented cache.

func New

func New(cfg config.CacheConfig) (Cache, error)

New selects a cache backend from config. The default (empty or "memory") is the process-local in-memory cache, so an app runs with no external Redis unless it explicitly opts in with driver "redis".

func NewInMemory

func NewInMemory(config.CacheConfig) (Cache, error)

NewInMemory builds a process-local cache. It needs no external service, so it is the default backend and lets an app run with no Redis. It is per-instance: entries are not shared across replicas, so use the Redis backend when a distributed cache is required.

func NewRedis

func NewRedis(cfg config.CacheConfig) (Cache, error)

NewRedis builds a Redis-backed cache from config, using the in-tree RESP client (no third-party Redis dependency). It does no I/O — connections dial lazily on first use.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL