Versions in this module Expand all Collapse all v0 v0.1.0 Oct 18, 2026 Changes in this version + const NoExpiry + var ErrBatchLength = errors.New("cache: batch keys and values must have equal length") + var ErrEmptyCoordinationOwner = errors.New("cache: coordination owner must not be empty") + var ErrEmptyNamespace = errors.New("cache: namespace must not be empty") + var ErrFillLeaseLost = errors.New("cache: fill lease lost") + var ErrInvalidLowerLayer = errors.New("cache: lower layer must have at least one upper layer") + var ErrInvalidTTL = errors.New("cache: ttl must be positive") + var ErrLeaseLost = errors.New("cache: lease is no longer owned") + var ErrLoaderPanic = errors.New("cache: loader panicked") + var ErrLockNotAcquired = errors.New("cache: lock not acquired") + var ErrNilCache = errors.New("cache: wrapped cache must not be nil") + var ErrNilCoordinationBackend = errors.New("cache: coordination backend must not be nil") + var ErrNilCoordinationLease = errors.New("cache: coordination backend returned a nil lease") + var ErrNilFillKeyFunc = errors.New("cache: fill key function must not be nil") + var ErrNilInvalidationHandler = errors.New("cache: invalidation handler must not be nil") + var ErrNilLease = errors.New("cache: locker returned a nil lease") + var ErrNilLoader = errors.New("cache: loader must not be nil") + var ErrNilLocker = errors.New("cache: locker must not be nil") + var ErrNilMessagingPublisher = errors.New("cache: messaging publisher must not be nil") + var ErrNilMessagingSubscriber = errors.New("cache: messaging subscriber must not be nil") + var ErrNilStore = errors.New("cache: store must not be nil") + var ErrNilSubscriptionFactory = errors.New("cache: subscription factory must not be nil") + var ErrNoInvalidationBus = errors.New("cache: no invalidation bus configured") + var ErrNoLayers = errors.New("cache: at least one layer is required") + var ErrUntypedValue = errors.New("cache: decoding an interface value requires a custom codec") + type BatchCache interface + GetMany func(context.Context, []K) ([]V, []bool, error) + InvalidateMany func(context.Context, []K) error + SetMany func(context.Context, []K, []V) error + SetManyWithTTL func(context.Context, []K, []V, time.Duration) error + type BatchStore interface + GetMany func(context.Context, string, []K) ([]Entry[V], []bool, error) + InvalidateMany func(context.Context, string, []K) error + SetMany func(context.Context, string, []K, []Entry[V]) error + type Cache interface + Get func(context.Context, K) (V, bool, error) + Invalidate func(context.Context, K) error + InvalidateAll func(context.Context) error + Set func(context.Context, K, V) error + SetWithTTL func(context.Context, K, V, time.Duration) error + type Codec interface + Decode func([]byte) (T, error) + Encode func(T) ([]byte, error) + func DefaultCodec[T any]() Codec[T] + type CoordinationLocker struct + func NewCoordinationLocker[K comparable](backend coordination.Backend, owner string, key FillKeyFunc[K]) (*CoordinationLocker[K], error) + func (l *CoordinationLocker[K]) Lock(ctx context.Context, namespace string, key K, ttl time.Duration) (Lease, error) + type Entry struct + ExpiresAt time.Time + Found bool + Value V + func (e Entry[V]) Expired(now time.Time) bool + func (e Entry[V]) NeverExpires() bool + type EntryCache interface + GetEntry func(context.Context, K) (Entry[V], bool, error) + SetEntry func(context.Context, K, Entry[V]) error + type Event struct + Err error + Layer int + Namespace string + Operation string + type FillKeyFunc func(namespace string, key K) (string, error) + type InvalidationBus interface + Publish func(context.Context, InvalidationEvent[K]) error + Subscribe func(context.Context, string, InvalidationHandler[K]) error + type InvalidationEvent struct + Generation uint64 + Key K + Kind InvalidationKind + Namespace string + type InvalidationHandler func(context.Context, InvalidationEvent[K]) error + type InvalidationKind uint8 + const InvalidateKey + const InvalidateNamespace + type LayeredOption func(*layeredConfig) + func WithLayerObserver(observer Observer) LayeredOption + func WithStrictLayerReads() LayeredOption + type LayeredStore struct + func NewLayeredWithInvalidationBus[K comparable, V any](layers []Store[K, V], bus InvalidationBus[K], options ...LayeredOption) (*LayeredStore[K, V], error) + func NewLayered[K comparable, V any](layers []Store[K, V], options ...LayeredOption) (*LayeredStore[K, V], error) + func (s *LayeredStore[K, V]) Get(ctx context.Context, namespace string, key K) (Entry[V], bool, error) + func (s *LayeredStore[K, V]) Invalidate(ctx context.Context, namespace string, key K) error + func (s *LayeredStore[K, V]) InvalidateAll(ctx context.Context, namespace string) error + func (s *LayeredStore[K, V]) ListenInvalidations(ctx context.Context, namespace string, lowerLayer int) error + func (s *LayeredStore[K, V]) Set(ctx context.Context, namespace string, key K, entry Entry[V]) error + type Lease interface + Refresh func(context.Context, time.Duration) error + Release func(context.Context) error + type Loader func(context.Context, K) (V, bool, error) + type Locker interface + Lock func(context.Context, string, K, time.Duration) (Lease, error) + type MessagingInvalidationBus struct + func NewMessagingInvalidationBus[K comparable](publisher messaging.Publisher[InvalidationEvent[K]], ...) (*MessagingInvalidationBus[K], error) + func (b *MessagingInvalidationBus[K]) Publish(ctx context.Context, event InvalidationEvent[K]) error + func (b *MessagingInvalidationBus[K]) Subscribe(ctx context.Context, namespace string, handler InvalidationHandler[K]) error + type ObservableLease interface + Done func() <-chan struct{} + type Observer interface + Observe func(context.Context, Event) + type PullThroughCache struct + func NewPullThrough[K comparable, V any](namespace string, wrapped Cache[K, V], loader Loader[K, V], ...) (*PullThroughCache[K, V], error) + func (c *PullThroughCache[K, V]) Get(ctx context.Context, key K) (V, bool, error) + func (c *PullThroughCache[K, V]) Invalidate(ctx context.Context, key K) error + func (c *PullThroughCache[K, V]) InvalidateAll(ctx context.Context) error + func (c *PullThroughCache[K, V]) Set(ctx context.Context, key K, value V) error + func (c *PullThroughCache[K, V]) SetWithTTL(ctx context.Context, key K, value V, ttl time.Duration) error + type PullThroughOption func(*pullThroughConfig[K]) error + func WithLoadOnLockError[K comparable]() PullThroughOption[K] + func WithLockPollInterval[K comparable](interval time.Duration) PullThroughOption[K] + func WithLocker[K comparable](locker Locker[K], leaseTTL time.Duration) PullThroughOption[K] + func WithNegativeTTL[K comparable](ttl time.Duration) PullThroughOption[K] + func WithStrictPullThroughReads[K comparable]() PullThroughOption[K] + type StandardCache struct + func New[K comparable, V any](namespace string, defaultTTL time.Duration, store Store[K, V]) (*StandardCache[K, V], error) + func (c *StandardCache[K, V]) Get(ctx context.Context, key K) (V, bool, error) + func (c *StandardCache[K, V]) GetEntry(ctx context.Context, key K) (Entry[V], bool, error) + func (c *StandardCache[K, V]) GetMany(ctx context.Context, keys []K) ([]V, []bool, error) + func (c *StandardCache[K, V]) Invalidate(ctx context.Context, key K) error + func (c *StandardCache[K, V]) InvalidateAll(ctx context.Context) error + func (c *StandardCache[K, V]) InvalidateMany(ctx context.Context, keys []K) error + func (c *StandardCache[K, V]) Set(ctx context.Context, key K, value V) error + func (c *StandardCache[K, V]) SetEntry(ctx context.Context, key K, entry Entry[V]) error + func (c *StandardCache[K, V]) SetMany(ctx context.Context, keys []K, values []V) error + func (c *StandardCache[K, V]) SetManyWithTTL(ctx context.Context, keys []K, values []V, ttl time.Duration) error + func (c *StandardCache[K, V]) SetWithTTL(ctx context.Context, key K, value V, ttl time.Duration) error + type Store interface + Get func(context.Context, string, K) (Entry[V], bool, error) + Invalidate func(context.Context, string, K) error + InvalidateAll func(context.Context, string) error + Set func(context.Context, string, K, Entry[V]) error + type SubscriptionFactory func(namespace string) messaging.Subscription