Documentation
¶
Overview ¶
Package cache provides a generic in-memory LRU (Least Recently Used) cache implementation. The cache stores any Go value by serializing it to bytes using MessagePack encoding, making it suitable for a wide variety of data types.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Key ¶ added in v0.3.1
type Key interface {
comparable
~string | ~[]byte | ~[12]byte | ~[16]byte
}
type LRU ¶ added in v0.3.1
LRU is a generic LRU cache that can store any value type.
func (*LRU[K, V]) Add ¶ added in v0.3.1
Add inserts a key-value pair into the cache. If the key already exists, its value is updated. Returns an error if the value cannot be serialized.
func (*LRU[K, V]) Bytes ¶ added in v0.3.1
Bytes returns the approximate memory usage of the cache in bytes, including both keys and serialized values.
func (*LRU[K, V]) Get ¶ added in v0.3.1
Get retrieves a value from the cache by its key. Returns the value and a boolean indicating whether the key was found.
func (*LRU[K, V]) Items ¶ added in v0.3.1
Items returns the number of items currently stored in the cache.
func (*LRU[K, V]) Remove ¶ added in v0.3.1
func (c *LRU[K, V]) Remove(key K)
Remove deletes an item from the cache by its key.
func (*LRU[K, V]) RemoveOldest ¶ added in v0.3.1
func (c *LRU[K, V]) RemoveOldest()
RemoveOldest removes the least recently used item from the cache.