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 ¶
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.