fifo

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

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

func (c *FIFOCache[K, V]) Algorithm() string

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]) Capacity

func (c *FIFOCache[K, V]) Capacity() int

Capacity returns the maximum number of items the cache can hold.

func (*FIFOCache[K, V]) Delete

func (c *FIFOCache[K, V]) Delete(key K) bool

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

func (c *FIFOCache[K, V]) DeleteMany(keys []K) map[K]bool

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

func (c *FIFOCache[K, V]) DeleteOldest() (k K, v V, ok bool)

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

func (c *FIFOCache[K, V]) Get(key K) (value V, ok bool)

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]) Has

func (c *FIFOCache[K, V]) Has(key K) bool

Has checks if a key exists in the cache.

func (*FIFOCache[K, V]) HasMany

func (c *FIFOCache[K, V]) HasMany(keys []K) map[K]bool

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]) Len

func (c *FIFOCache[K, V]) Len() int

Len returns the current number of items in the cache.

func (*FIFOCache[K, V]) Peek

func (c *FIFOCache[K, V]) Peek(key K) (value V, ok bool)

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

func (c *FIFOCache[K, V]) Range(f func(K, V) bool)

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.

func (*FIFOCache[K, V]) SizeBytes

func (c *FIFOCache[K, V]) SizeBytes() int64

SizeBytes returns the total size of all cache entries in bytes.

func (*FIFOCache[K, V]) Values

func (c *FIFOCache[K, V]) Values() []V

Values returns all values currently in the cache.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL