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 Cache ¶
type Cache[V any] struct { // contains filtered or unexported fields }
Cache is a generic LRU cache that can store any value type.
func (*Cache[V]) Add ¶
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 (*Cache[V]) Bytes ¶
Bytes returns the approximate memory usage of the cache in bytes, including both keys and serialized values.
func (*Cache[V]) Get ¶
Get retrieves a value from the cache by its key. Returns the value and a boolean indicating whether the key was found.
func (*Cache[V]) RemoveOldest ¶
func (c *Cache[V]) RemoveOldest()
RemoveOldest removes the least recently used item from the cache.