Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FIFO ¶
type FIFO[T comparable] struct { // contains filtered or unexported fields }
FIFO implements the First In, First Out eviction policy.
type LFU ¶
type LFU[T comparable] struct { // contains filtered or unexported fields }
LFU implements the Least Frequently Used eviction policy.
type Policy ¶
type Policy[T comparable] interface { Put(key T) (T, bool) // Adds a key to the cache, returns the evicted key if any. Delete(key T) // Removes a key from the cache. Evict() (T, bool) // Evicts a key from the cache based on the policy. Reset() // Clears all keys from the cache. Size() int // Returns the current number of keys in the cache. }
Policy defines the interface for cache eviction policies.
func NewFIFO ¶
func NewFIFO[T comparable](capacity int) Policy[T]
NewFIFO creates a new FIFO cache with the given capacity.
func NewLFU ¶
func NewLFU[T comparable](capacity int) Policy[T]
NewLFU creates a new LFU cache with the given capacity.
func NewLRU ¶
func NewLRU[T comparable](capacity int) Policy[T]
NewLRU creates a new lru cache with the given capacity.
Click to show internal directories.
Click to hide internal directories.