Documentation
¶
Index ¶
- type FIFOCache
- func (c *FIFOCache[K, V]) Algorithm() string
- func (c *FIFOCache[K, V]) All() map[K]V
- func (c *FIFOCache[K, V]) Capacity() int
- func (c *FIFOCache[K, V]) Delete(key K) bool
- func (c *FIFOCache[K, V]) DeleteMany(keys []K) map[K]bool
- func (c *FIFOCache[K, V]) DeleteOldest() (k K, v V, ok bool)
- func (c *FIFOCache[K, V]) Get(key K) (value V, ok bool)
- func (c *FIFOCache[K, V]) GetMany(keys []K) (map[K]V, []K)
- func (c *FIFOCache[K, V]) Has(key K) bool
- func (c *FIFOCache[K, V]) HasMany(keys []K) map[K]bool
- func (c *FIFOCache[K, V]) Keys() []K
- func (c *FIFOCache[K, V]) Len() int
- func (c *FIFOCache[K, V]) Peek(key K) (value V, ok bool)
- func (c *FIFOCache[K, V]) PeekMany(keys []K) (map[K]V, []K)
- func (c *FIFOCache[K, V]) Purge()
- func (c *FIFOCache[K, V]) Range(f func(K, V) bool)
- func (c *FIFOCache[K, V]) Set(key K, value V)
- func (c *FIFOCache[K, V]) SetMany(items map[K]V)
- func (c *FIFOCache[K, V]) SizeBytes() int64
- func (c *FIFOCache[K, V]) Values() []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FIFOCache ¶
type FIFOCache[K comparable, V any] struct { // contains filtered or unexported fields }
FIFOCache is a First In, First Out cache implementation. It is not safe for concurrent access and should be wrapped with a thread-safe layer if needed.
func NewFIFOCache ¶
func NewFIFOCache[K comparable, V any](capacity int) *FIFOCache[K, V]
NewFIFOCache creates a new FIFO cache with the specified capacity. The cache will evict the first inserted items when it reaches capacity.
func NewFIFOCacheWithEvictionCallback ¶
func NewFIFOCacheWithEvictionCallback[K comparable, V any](capacity int, onEviction base.EvictionCallback[K, V]) *FIFOCache[K, V]
NewFIFOCacheWithEvictionCallback creates a new FIFO cache with the specified capacity and eviction callback. The callback will be called whenever an item is evicted from the cache.
func (*FIFOCache[K, V]) Algorithm ¶
Algorithm returns the name of the eviction algorithm used by the cache.
func (*FIFOCache[K, V]) All ¶ added in v0.9.0
func (c *FIFOCache[K, V]) All() map[K]V
All returns all key-value pairs in the cache.
func (*FIFOCache[K, V]) Delete ¶
Delete removes a key from the cache. Returns true if the key was found and removed, false otherwise. Time complexity: O(1) average case.
func (*FIFOCache[K, V]) DeleteMany ¶
DeleteMany removes multiple keys from the cache. Returns a map where keys are the input keys and values indicate if the key was found and removed.
func (*FIFOCache[K, V]) DeleteOldest ¶
DeleteOldest removes and returns the oldest item in the cache. Returns the key, value, and a boolean indicating if an item was found.
func (*FIFOCache[K, V]) Get ¶
Get retrieves a value from the cache without changing its position. Returns the value and a boolean indicating if the key was found.
func (*FIFOCache[K, V]) GetMany ¶
func (c *FIFOCache[K, V]) GetMany(keys []K) (map[K]V, []K)
GetMany retrieves multiple values from the cache. Returns a map of found key-value pairs and a slice of missing keys.
func (*FIFOCache[K, V]) HasMany ¶
HasMany checks if multiple keys exist in the cache. Returns a map where keys are the input keys and values indicate existence.
func (*FIFOCache[K, V]) Keys ¶
func (c *FIFOCache[K, V]) Keys() []K
Keys returns all keys currently in the cache.
func (*FIFOCache[K, V]) Peek ¶
Peek retrieves a value from the cache without updating the access order. Returns the value and a boolean indicating if the key was found.
func (*FIFOCache[K, V]) PeekMany ¶
func (c *FIFOCache[K, V]) PeekMany(keys []K) (map[K]V, []K)
PeekMany retrieves multiple values from the cache without updating access order. Returns a map of found key-value pairs and a slice of missing keys.
func (*FIFOCache[K, V]) Purge ¶
func (c *FIFOCache[K, V]) Purge()
Purge removes all keys and values from the cache.
func (*FIFOCache[K, V]) Range ¶
Range iterates over all key-value pairs in the cache. The iteration stops if the function returns false.
func (*FIFOCache[K, V]) Set ¶
func (c *FIFOCache[K, V]) Set(key K, value V)
Set stores a key-value pair in the cache. If the key already exists, its value is updated but its position remains unchanged. If the cache is at capacity, the first inserted item is evicted. Time complexity: O(1) average case, O(n) worst case when eviction occurs.
func (*FIFOCache[K, V]) SetMany ¶
func (c *FIFOCache[K, V]) SetMany(items map[K]V)
SetMany stores multiple key-value pairs in the cache. This is more efficient than calling Set multiple times.