Versions in this module Expand all Collapse all v1 v1.0.2 Feb 18, 2026 v1.0.1 Feb 18, 2026 Changes in this version + var ErrClosed = errors.New("cache: cache closed") + var ErrInvalidKey = errors.New("cache: invalid key") + var ErrInvalidValue = errors.New("cache: invalid value") + var ErrNotFound = errors.New("cache: key not found") + var ErrTypeAssertion = errors.New("cache: type assertion failed") + type BatchCache interface + DeleteMany func(ctx context.Context, keys []string) error + GetMany func(ctx context.Context, keys []string) (map[string]T, error) + SetMany func(ctx context.Context, items map[string]T, ttl time.Duration) error + func NewBatch[T any](store Store, opts ...Option) BatchCache[T] + type Cache interface + Clear func(ctx context.Context) error + Close func() error + Delete func(ctx context.Context, key string) error + Get func(ctx context.Context, key string) (T, error) + Set func(ctx context.Context, key string, value T, ttl time.Duration) error + func New[T any](store Store, opts ...Option) Cache[T] + type ChainCache interface + GetLayers func() []Cache[T] + func NewChain[T any](layers ...Cache[T]) ChainCache[T] + type Codec interface + Decode func(data []byte, v any) error + Encode func(v any) ([]byte, error) + type Config struct + Codec Codec + DefaultTTL time.Duration + Metrics *Metrics + OnError func(error) + SingleFlight bool + Store Store + type LoaderCache interface + GetOrLoad func(ctx context.Context, key string, loader LoaderFunc[T]) (T, error) + func NewLoader[T any](store Store, opts ...Option) LoaderCache[T] + type LoaderFunc func(ctx context.Context, key string) (T, error) + type Metrics struct + Errors atomic.Int64 + Evictions atomic.Int64 + Hits atomic.Int64 + Misses atomic.Int64 + func (m *Metrics) HitRate() float64 + type Option func(*Config) + func WithCodec(codec Codec) Option + func WithMetrics(metrics *Metrics) Option + func WithOnError(handler func(error)) Option + func WithSingleFlight() Option + func WithTTL(ttl time.Duration) Option + type Store interface + Clear func(ctx context.Context) error + Close func() error + Delete func(ctx context.Context, key string) error + Get func(ctx context.Context, key string) ([]byte, error) + Set func(ctx context.Context, key string, value []byte, ttl time.Duration) error