Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K any, V any] interface { Stats() (int64, int64) Get(ctx context.Context, key K) (V, error) }
Cache is an abstraction of a simple cache.
type ExtendedCache ¶
type ExtendedCache[K comparable, V Identifiable[K]] interface { Cache[K, V] Map(ctx context.Context, keys []K) (map[K]V, error) }
ExtendedCache is an extension of the simple cache abstraction that adds mapping functionality.
type ExtendedGetter ¶
type ExtendedGetter[K comparable, V Identifiable[K]] interface { Getter[K, V] FindMany(ctx context.Context, keys []K) ([]V, error) }
type ExtendedTTLCache ¶
type ExtendedTTLCache[K constraints.Ordered, V Identifiable[K]] struct { TTLCache[K, V] // contains filtered or unexported fields }
ExtendedTTLCache is an extended version of the TTLCache.
func NewExtended ¶
func NewExtended[K constraints.Ordered, V Identifiable[K]]( getter ExtendedGetter[K, V], maxAge time.Duration, ) *ExtendedTTLCache[K, V]
NewExtended creates a new TTLCacheExtended instance and a background routine that periodically purges stale items.
type Identifiable ¶
type Identifiable[K comparable] interface { Identifier() K }
type TTLCache ¶
type TTLCache[K comparable, V any] struct { // contains filtered or unexported fields }
TTLCache is a generic TTL based cache that stores objects for the specified period. The TTLCache has no maximum capacity, so the idea is to store objects for short period. The goal of the TTLCache is to reduce database load. Every instance of TTLCache has a background routine that purges stale items.
func New ¶
New creates a new TTLCache instance and a background routine that periodically purges stale items.