Versions in this module Expand all Collapse all v0 v0.1.1 Jan 3, 2024 v0.1.0 Jan 3, 2024 Changes in this version + var DecayFactor = 0.25 + var ErrRecordNotFound = errors.New("record not found") + var ExpiryDeviation = 0.05 + func GenerateCacheKey(arg any) string + type Cache interface + Get func(ctx context.Context, key string) (T, error) + Set func(ctx context.Context, key string, value T) error + type CacheConfig struct + Prefix string + type CacheKeyGenerator interface + GetCacheKey func() string + type CacheOption func(*CacheConfig) + func WithKeyPrefix(prefix string) CacheOption + type ChainCache struct + func NewChainCache[T any](caches ...Cache[T]) *ChainCache[T] + func (c ChainCache[T]) Get(ctx context.Context, key string) (value T, err error) + func (c ChainCache[T]) Set(ctx context.Context, key string, value T) error + type ChainCacheValue struct + Caches []Cache[T] + Key string + Value T + type LoadFunction func(T) (K, error) + type LoadFunctionCtx func(context.Context, T) (K, error) + type LoadableCache struct + func NewLoadableCache[T, K any](cache Cache[K]) *LoadableCache[T, K] + func (c *LoadableCache[T, K]) Load(fn LoadFunction[T, K], arg T) (K, error) + func (c *LoadableCache[T, K]) LoadCtx(ctx context.Context, fn LoadFunctionCtx[T, K], arg T) (K, error) + type LoadableL2Cache struct + func NewLoadableL2Cache[T, K any](client *redis.Client, expiration time.Duration) *LoadableL2Cache[T, K] + type MemoryCache struct + func NewMemoryCache[T any](expiration time.Duration, options ...CacheOption) *MemoryCache[T] + func (s *MemoryCache[T]) Set(ctx context.Context, key string, value T) error + func (s MemoryCache[T]) Delete(key string) error + func (s MemoryCache[T]) Get(ctx context.Context, key string) (T, error) + type RedisCache struct + func NewRedisCache[T any](client *redis.Client, expiration time.Duration, options ...CacheOption) *RedisCache[T] + func (s RedisCache[T]) Get(ctx context.Context, key string) (value T, err error) + func (s RedisCache[T]) Set(ctx context.Context, key string, value T) error + type SingleFlight interface + Do func(fn LoadFunction[T, K], arg T) (K, error) + DoCtx func(ctx context.Context, fn LoadFunctionCtx[T, K], arg T) (K, error) + DoEx func(fn LoadFunction[T, K], arg T) (val K, fresh bool, err error) + DoExCtx func(ctx context.Context, fn LoadFunctionCtx[T, K], arg T) (val K, fresh bool, err error) + func NewSingleFlight[T, K any]() SingleFlight[T, K]