Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // it can be changed and default value is 0.05 ExpiryDeviation = 0.05 ErrRecordNotFound = errors.New("record not found") )
View Source
var (
// it can be changed and default value is 0.25
DecayFactor = 0.25
)
Functions ¶
func GenerateCacheKey ¶
GenerateCacheKey returns the cache key for the given key object by returning the key if type is string or by computing a checksum of key structure if its type is other than string
Types ¶
type CacheConfig ¶
type CacheConfig struct { // key prefix Prefix string }
type CacheKeyGenerator ¶
type CacheKeyGenerator interface {
GetCacheKey() string
}
type CacheOption ¶
type CacheOption func(*CacheConfig)
func WithKeyPrefix ¶
func WithKeyPrefix(prefix string) CacheOption
type ChainCache ¶
type ChainCache[T any] struct { // contains filtered or unexported fields }
func NewChainCache ¶
func NewChainCache[T any](caches ...Cache[T]) *ChainCache[T]
NewChainCache instanciates a new cache that combine other caches
type ChainCacheValue ¶
type LoadFunction ¶
type LoadableCache ¶
type LoadableCache[T, K any] struct { // contains filtered or unexported fields }
func NewLoadableCache ¶
func NewLoadableCache[T, K any](cache Cache[K]) *LoadableCache[T, K]
NewLoadableCache instanciates a new cache that uses a function to load data
func (*LoadableCache[T, K]) Load ¶
func (c *LoadableCache[T, K]) Load(fn LoadFunction[T, K], arg T) (K, error)
Load returns the object stored in cache
func (*LoadableCache[T, K]) LoadCtx ¶
func (c *LoadableCache[T, K]) LoadCtx(ctx context.Context, fn LoadFunctionCtx[T, K], arg T) (K, error)
LoadCtx returns the object stored in cache with context
type LoadableL2Cache ¶
type LoadableL2Cache[T, K any] struct { *LoadableCache[T, K] }
func NewLoadableL2Cache ¶
func NewLoadableL2Cache[T, K any](client *redis.Client, expiration time.Duration) *LoadableL2Cache[T, K]
type MemoryCache ¶
type MemoryCache[T any] struct { // contains filtered or unexported fields }
func NewMemoryCache ¶
func NewMemoryCache[T any](expiration time.Duration, options ...CacheOption) *MemoryCache[T]
func (MemoryCache[T]) Delete ¶
func (s MemoryCache[T]) Delete(key string) error
type RedisCache ¶
type RedisCache[T any] struct { // contains filtered or unexported fields }
func NewRedisCache ¶
func NewRedisCache[T any](client *redis.Client, expiration time.Duration, options ...CacheOption) *RedisCache[T]
type SingleFlight ¶
type SingleFlight[T, K any] interface { Do(fn LoadFunction[T, K], arg T) (K, error) DoEx(fn LoadFunction[T, K], arg T) (val K, fresh bool, err error) DoCtx(ctx context.Context, fn LoadFunctionCtx[T, K], arg T) (K, error) DoExCtx(ctx context.Context, fn LoadFunctionCtx[T, K], arg T) (val K, fresh bool, err error) }
func NewSingleFlight ¶
func NewSingleFlight[T, K any]() SingleFlight[T, K]
NewSingleFlight returns a generic single flight.
Click to show internal directories.
Click to hide internal directories.