Documentation
¶
Overview ¶
Package cache provides different cache type (e.g. Key/Value) with pluggable backends.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNotFound error = errors.New("not found")
ErrNotFound is returned by LoadFunc to indicate the requested key was not found.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K comparable, V any] interface { // Get gets the cached value for the given key. // Error ErrNotFound indicates a cache miss. Get(ctx context.Context, key K) (V, error) }
Cache defines the basic cache interface used to retrieve a cached value for a key.
type KeyValue ¶
type KeyValue[K comparable, V any] interface { Cache[K, V] // Put adds key-value association to the cache. // Any previously established key-value association // is overwritten. Put(ctx context.Context, key K, value V) // Delete removes the given key from the cache. Delete(ctx context.Context, key K) io.Closer }
KeyValue defines the key-value cache type.
type LoadFunc ¶
type LoadFunc[K comparable, V any] func(ctx context.Context, key K) (V, error)
LoadFunc defines the signature for functions responsible for loading cache values based on the value's key.
type NoCache ¶
type NoCache[K comparable, V any] struct { Value V Found bool }
NoCache provides a cache implementation without any caching at all. This is suitable for test scenarios or to disable caching.
Click to show internal directories.
Click to hide internal directories.