cache

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

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](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.

func NewTimeoutEviction

func NewTimeoutEviction[K comparable](timeout time.Duration, evict func([]K)) *timeoutEviction[K]

Types

type EvictionPolicy

type EvictionPolicy[K comparable] interface {
	// Push adds a key and must be invoked under write-lock
	Push(K)
}

type Map

type Map[K comparable, V any] interface {
	Get(K) (V, bool)
	Put(K, V)
	Update(K, func(bool, V) (bool, V)) bool
	Delete(...K)
	Len() int
}

Jump to

Keyboard shortcuts

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