Documentation ¶
Overview ¶
Package lru implements a generic Least Recently Used (LRU) cache with support for "spam" items. The cache maintains a maximum number of items, evicting the least recently used item when the limit is reached. Items can be added, retrieved, and deleted from the cache. Regular items are moved to the front of the cache when accessed or updated, while "spam" items maintain their position. This allows for preferential treatment of non-spam items in terms of retention, while still caching spam items. The cache is safe for concurrent use.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶ added in v0.0.31
type Cache[K comparable, V any] struct { // contains filtered or unexported fields }
Cache is a generic LRU cache that supports "spam" items.
func NewCache ¶
func NewCache[K comparable, V any](maxItems int) *Cache[K, V]
NewCache creates a new LRU cache with the specified maximum number of items.
func (*Cache[K, V]) Delete ¶ added in v0.0.31
func (c *Cache[K, V]) Delete(key K)
Delete removes an item from the cache if it exists.
func (*Cache[K, V]) Get ¶ added in v0.0.31
Get retrieves an item from the cache, moving non-spam items to the front. It returns the value and a boolean indicating whether the key was found.