Versions in this module Expand all Collapse all v1 v1.0.0 Aug 25, 2026 Changes in this version + var ErrBackend = errors.New("cache backend error") + var ErrBatchTooLarge = errors.New("cache batch too large") + var ErrCapacity = errors.New("cache capacity exceeded") + var ErrClosed = errors.New("cache backend closed") + var ErrDecode = errors.New("cache decode error") + var ErrInvalidConfig = errors.New("invalid cache configuration") + var ErrInvalidKey = errors.New("invalid cache key") + var ErrInvalidPolicy = errors.New("invalid cache policy") + var ErrInvalidRecord = errors.New("invalid cache record") + var ErrInvalidTTL = errors.New("invalid cache TTL") + var ErrKeyTooLarge = errors.New("cache key too large") + var ErrLoader = errors.New("cache loader error") + var ErrLoaderPanic = errors.New("cache loader panic") + var ErrMiss = errors.New("cache miss") + var ErrOwnershipLost = errors.New("cache ownership lost") + var ErrOwnershipUnsupported = errors.New("cache ownership validation unsupported") + var ErrRecursiveLoad = errors.New("recursive cache load") + var ErrSchemaMismatch = errors.New("cache schema mismatch") + var ErrValueTooLarge = errors.New("cache value too large") + var ErrWaiterLimit = errors.New("cache waiter limit exceeded") + type Backend interface + Delete func(context.Context, string) (bool, error) + Get func(context.Context, string) (Record, bool, error) + Set func(context.Context, string, Record, Condition) (bool, error) + type BulkResult struct + Err error + Key K + type Cache struct + func New[K, V any](config Config[K, V]) (*Cache[K, V], error) + func (c *Cache[K, V]) Add(ctx context.Context, logical K, value V) (bool, error) + func (c *Cache[K, V]) Close() error + func (c *Cache[K, V]) Delete(ctx context.Context, logical K) (err error) + func (c *Cache[K, V]) DeleteMany(ctx context.Context, keys []K) ([]MutationResult[K], error) + func (c *Cache[K, V]) Get(ctx context.Context, logical K) (result Result[V], err error) + func (c *Cache[K, V]) GetMany(ctx context.Context, keys []K) ([]BulkResult[K, V], error) + func (c *Cache[K, V]) GetOrLoad(ctx context.Context, logical K, loader Loader[K, V]) (Result[V], error) + func (c *Cache[K, V]) Replace(ctx context.Context, logical K, value V) (bool, error) + func (c *Cache[K, V]) Set(ctx context.Context, logical K, value V) error + func (c *Cache[K, V]) SetIfOwned(ctx context.Context, logical K, value V, guard OwnershipGuard) error + func (c *Cache[K, V]) SetMany(ctx context.Context, entries []Entry[K, V]) ([]MutationResult[K], error) + func (c *Cache[K, V]) SetNegativeIfOwned(ctx context.Context, logical K, guard OwnershipGuard) error + type Clock interface + Now func() time.Time + type Codec interface + Decode func([]byte) (V, error) + Encode func(V) ([]byte, error) + type Condition uint8 + const IfAbsent + const IfPresent + const Unconditional + type Config struct + Backend Backend + Clock Clock + Codec Codec[V] + Jitter JitterSource + Keys KeySpace[K] + Load LoadPolicy + MaxBatch int + MaxValue int + Observer Observer + TTL TTLPolicy + type Entry struct + Key K + Value V + type Error struct + Cause error + Kind ErrorKind + Operation Operation + func (e *Error) Error() string + func (e *Error) Unwrap() []error + type ErrorKind uint8 + const BackendError + const DecodeError + const InvalidKeyError + const LimitError + const LoaderError + const PolicyError + const SchemaMismatchError + type Event struct + Duration time.Duration + Operation Operation + Outcome Outcome + Size int + type JSONCodec struct + MaxEncodedSize int + Version byte + func (c JSONCodec[V]) Decode(encoded []byte) (V, error) + func (c JSONCodec[V]) Encode(value V) ([]byte, error) + type JitterSource interface + Duration func(time.Duration) time.Duration + type KeyEncoder interface + EncodeKey func(K) ([]byte, error) + type KeySpace struct + func NewKeySpace[K any](namespace string, name string, version uint32, encoder KeyEncoder[K], ...) (KeySpace[K], error) + func (s KeySpace[K]) Key(logical K) (string, error) + type LoadPolicy struct + MaxConcurrent int + MaxWaitersPerKey int + NegativeTTL time.Duration + RefreshJitter time.Duration + StaleIfError bool + StaleWhileRevalidate bool + type LoadResult struct + Found bool + Value V + type Loader func(context.Context, K) (LoadResult[V], error) + type MutationResult struct + Err error + Key K + type Observer interface + Observe func(context.Context, Event) error + type Operation string + const OperationDelete + const OperationEvict + const OperationExpire + const OperationGet + const OperationLoad + const OperationSet + type Outcome string + const OutcomeError + const OutcomeEvicted + const OutcomeExpired + const OutcomeHit + const OutcomeMiss + const OutcomeNegative + const OutcomeRejected + const OutcomeStale + const OutcomeSuccess + type OwnershipBackend interface + SetIfOwned func(context.Context, string, Record, OwnershipGuard) error + type OwnershipGuard interface + Owner func() string + StorageKey func() string + Token func() string + type RandomJitter struct + func (RandomJitter) Duration(upperBound time.Duration) time.Duration + type Record struct + ExpiresAt time.Time + Negative bool + Payload []byte + StaleAt time.Time + func (r Record) Clone() Record + func (r Record) Validate() error + type Result struct + Negative bool + State State + Value V + type State uint8 + const Hit + const Miss + const Stale + type StringKeyEncoder struct + func (StringKeyEncoder) EncodeKey(key string) ([]byte, error) + type SystemClock struct + func (SystemClock) Now() time.Time + type TTLPolicy struct + Sliding bool + StaleFor time.Duration + TTL time.Duration + func (p TTLPolicy) Validate() error