memory

package
v0.1.31 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FirstInFirstOut = EvictionPolicy(iota)
	LeastRecentlyUsed
	LeastFrequentlyUsed
)

Variables

View Source
var (
	DefaultKeyValueCacheConfig = keyValueCacheConfig{
								// contains filtered or unexported fields
	}
	DefaultHistoricalKeyValueCacheConfig = historicalKeyValueCacheConfig{
											// contains filtered or unexported fields
	}
)

Functions

func NewHistoricalKeyValueCache

func NewHistoricalKeyValueCache[T any](opts ...KeyValueCacheOptionFn) (*historicalKeyValueCache[T], error)

NewHistoricalKeyValueCache creates a new historicalKeyValueCache with the configuration generated by applying the given option functions to the DefaultHistoricalKeyValueCacheConfig.

func NewKeyValueCache

func NewKeyValueCache[T any](opts ...KeyValueCacheOptionFn) (*keyValueCache[T], error)

NewKeyValueCache creates a new keyValueCache with the configuration generated by the given option functions.

Types

type EvictionPolicy

type EvictionPolicy int64

EvictionPolicy determines which values to remove when the number of keys in the cache exceeds maxKeys.

type KeyValueCacheOptionFn

type KeyValueCacheOptionFn func(keyValueConfigI) error

KeyValueCacheOptionFn is a function which receives a keyValueCacheConfig for configuration.

func WithEvictionPolicy

func WithEvictionPolicy(policy EvictionPolicy) KeyValueCacheOptionFn

WithEvictionPolicy sets the eviction policy.

func WithMaxKeys

func WithMaxKeys(maxKeys int64) KeyValueCacheOptionFn

WithMaxKeys sets the maximum number of distinct key/value pairs the cache will hold before evicting according to the configured eviction policy.

func WithMaxVersionAge

func WithMaxVersionAge(numRetainedVersions int64) KeyValueCacheOptionFn

WithMaxVersionAge sets the given maxVersionAge on the configuration; if 0, no historical pruning is performed. It can ONLY be used in the context of a HistoricalKeyValueCache.

func WithNoTTL added in v0.0.14

func WithNoTTL() KeyValueCacheOptionFn

WithNoTTL effectively disables the cache. Useful for testing.

func WithTTL

func WithTTL(ttl time.Duration) KeyValueCacheOptionFn

WithTTL sets the time-to-live for cached values. Values older than the TTL MAY NOT be evicted immediately, but are NEVER considered as cache hits. NOTE: TTL is ignored by the HistoricalKeyValueCache.

Jump to

Keyboard shortcuts

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