cache

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2025 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithCache added in v0.28.0

func WithCache[R any](cache Cache, cfg *Cfg, cacheKey []byte, onCacheMiss func() (*R, error)) (*R, error)

Types

type Cache

type Cache interface {
	// EvictShortLiving - notify the cache that all short living elements cached before the events should be considered as evicted.
	EvictShortLiving()

	// DisableShortLiving disables the caching of short-living elements.
	DisableShortLiving()

	// IsEvicted - based on the eviction event and the time of caching, calculates whether the key was evicted
	IsEvicted(key []byte, originalTTL time.Duration) bool

	Set(key []byte, value any, ttl time.Duration) bool
	Get(key []byte) (value any, ok bool)
	Remove(key []byte)
}

func NewCache

func NewCache(nrElems int, logger log.Logger) (Cache, error)

func NewNoOpCache added in v1.0.0

func NewNoOpCache() Cache

func NewRistrettoCacheWithEviction added in v0.24.0

func NewRistrettoCacheWithEviction(nrElems int, logger log.Logger) (Cache, error)

NewRistrettoCacheWithEviction returns a new ristrettoCache.

type Cfg added in v0.28.0

type Cfg struct {
	Type        Strategy
	DynamicType func() Strategy
}

type Strategy added in v0.28.0

type Strategy uint8
const (
	NoCache     Strategy = iota
	LatestBatch Strategy = iota
	LongLiving  Strategy = iota
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL