package lru

Import Path
	gorm.io/gorm/internal/lru (on go.dev)

Dependency Relation
	imports 2 packages, and imported by one package

Involved Source Files lru.go
Package-Level Type Names (total 4)
/* sort by: | */
Type Parameters: K: comparable V: any Entry is an LRU Entry The expiry bucket item was put in, optional The time this element would be cleaned up, optional The LRU Key of this element. The Value stored with this element. PrevEntry returns the previous list element or nil. func (*Entry)[K, V].PrevEntry() *Entry[K, V] func (*LruList)[K, V].Back() *Entry[K, V] func (*LruList)[K, V].PushFront(k K, v V) *Entry[K, V] func (*LruList)[K, V].PushFrontExpirable(k K, v V, expiresAt time.Time) *Entry[K, V] func (*LruList)[K, V].MoveToFront(e *Entry[K, V]) func (*LruList)[K, V].Remove(e *Entry[K, V]) V
Type Parameters: K: comparable V: any EvictCallback is used to get a callback when a cache entry is evicted func NewLRU[K, V](size int, onEvict EvictCallback[K, V], ttl time.Duration) *LRU[K, V]
Type Parameters: K: comparable V: any LRU implements a thread-safe LRU with expirable entries. Add adds a value to the cache. Returns true if an eviction occurred. Returns false if there was no eviction: the item was already in the cache, or the size was not exceeded. Cap returns the capacity of the cache Contains checks if a key is in the cache, without updating the recent-ness or deleting it for being stale. Get looks up a key's value from the cache. GetOldest returns the oldest entry (*LRU[K, V]) KeyValues() map[K]V Keys returns a slice of the keys in the cache, from oldest to newest. Expired entries are filtered out. Len returns the number of items in the cache. Peek returns the key value (or undefined if not found) without updating the "recently used"-ness of the key. Purge clears the cache completely. onEvict is called for each evicted key. Remove removes the provided key from the cache, returning if the key was contained. RemoveOldest removes the oldest item from the cache. Resize changes the cache size. Size of 0 means unlimited. Values returns a slice of the values in the cache, from oldest to newest. Expired entries are filtered out. func NewLRU[K, V](size int, onEvict EvictCallback[K, V], ttl time.Duration) *LRU[K, V]
Type Parameters: K: comparable V: any LruList represents a doubly linked list. The zero Value for LruList is an empty list ready to use. Back returns the last element of list l or nil if the list is empty. Init initializes or clears list l. Length returns the number of elements of list l. The complexity is O(1). MoveToFront moves element e to the front of list l. If e is not an element of l, the list is not modified. The element must not be nil. PushFront inserts a new element e with value v at the front of list l and returns e. PushFrontExpirable inserts a new expirable element e with Value v at the front of list l and returns e. Remove removes e from its list, decrements l.len func NewList[K, V]() *LruList[K, V] func (*LruList)[K, V].Init() *LruList[K, V]
Package-Level Functions (total 2)
Type Parameters: K: comparable V: any NewList returns an initialized list.
Type Parameters: K: comparable V: any NewLRU returns a new thread-safe cache with expirable entries. Size parameter set to 0 makes cache of unlimited size, e.g. turns LRU mechanism off. Providing 0 TTL turns expiring off. Delete expired entries every 1/100th of ttl value. Goroutine which deletes expired entries runs indefinitely.