Documentation
¶
Index ¶
- func NewLRUCache[K comparable, V any](size, buffer int, onEvict func(map[K]V)) *evictionCache[K, V]
- func NewLRUEviction[K comparable](size, buffer int, evict func([]K)) *lruEviction[K]
- func NewMapCache[K comparable, V any]() *mapCache[K, V]
- func NewTimeoutCache[K comparable, V any](ctx context.Context, evictionTimeout time.Duration, onEvict func(map[K]V)) *evictionCache[K, V]
- func NewTimeoutEviction[K comparable](ctx context.Context, timeout time.Duration, evict func([]K)) *timeoutEviction[K]
- type EvictionPolicy
- type Map
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewLRUCache ¶
func NewLRUCache[K comparable, V any](size, buffer int, onEvict func(map[K]V)) *evictionCache[K, V]
NewLRUCache creates a cache with limited size with LRU eviction policy. It is guaranteed that at least size elements can be kept in the cache. The cache is cleaned up when the cache is full, i.e. it contains size + buffer elements
func NewLRUEviction ¶
func NewLRUEviction[K comparable](size, buffer int, evict func([]K)) *lruEviction[K]
func NewMapCache ¶
func NewMapCache[K comparable, V any]() *mapCache[K, V]
NewMapCache creates a dummy implementation of the Cache interface. It is backed by a map with unlimited capacity.
func NewTimeoutCache ¶
func NewTimeoutCache[K comparable, V any](ctx context.Context, evictionTimeout time.Duration, onEvict func(map[K]V)) *evictionCache[K, V]
NewTimeoutCache creates a cache that keeps elements for evictionTimeout time. An element might return even if it is marked stale. The background cleanup goroutine stops when ctx is cancelled. A non-positive evictionTimeout disables eviction; see NewTimeoutEviction.
func NewTimeoutEviction ¶
func NewTimeoutEviction[K comparable](ctx context.Context, timeout time.Duration, evict func([]K)) *timeoutEviction[K]
NewTimeoutEviction returns an eviction policy that evicts entries older than timeout, driven by a background goroutine that stops when ctx is cancelled.
A non-positive timeout disables eviction entirely and no goroutine is started. Note that time.NewTicker panics on a non-positive duration, so this guard is what keeps a misconfigured timeout from taking the process down from inside the goroutine.
Types ¶
type EvictionPolicy ¶
type EvictionPolicy[K comparable] interface { // Push adds a key and must be invoked under write-lock Push(K) }