Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Eviction ¶
type Eviction interface {
// Get retrieves a value from the eviction cache given a key.
Get(key string) (any, bool)
// Put adds a key-value pair to the eviction cache.
Put(key string, value any)
// Delete removes a key from the eviction cache.
Delete(key string)
// Clear clears the eviction cache
Clear()
}
Eviction is the interface that defines the methods for an eviction policy.
type LFUResource ¶
type LFUResource interface {
// Key returns key for the eviction entry.
Key() string
// IncrementFrequency increments the key access frequency by 1.
IncrementFrequency()
// Frequency returns the frequency for the entry.
Frequency() int
// Value return the value for the entry.
Value() any
// Set sets the value for the entry.
Set(any)
}
type Options ¶
type Options struct {
// Capacity is the maximum number of items that can be stored in the eviction cache.
// After this capacity is reached, the cache will start evicting items based on the eviction policy.
// Default value is 100.
Capacity int
// Policy is the eviction policy to be used.
Policy Policy
// DeleteFinalizer is the finalizer function that is called when an item is deleted from the cache.
DeleteFinalizer func(key string, value any)
// EvictFinalizer is the finalizer function that is called when an item is evicted from the cache.
EvictFinalizer func(key string, value any)
}
Options holds the configuration for the eviction cache.
type PriorityQueue ¶
type PriorityQueue []*pqItem
PriorityQueue is a priority queue of pqItems
func (PriorityQueue) Len ¶
func (pq PriorityQueue) Len() int
Len returns the length of the priority queue
func (PriorityQueue) Less ¶
func (pq PriorityQueue) Less(i, j int) bool
Less returns true if the item at index i expires before the item at index j
func (*PriorityQueue) Pop ¶
func (pq *PriorityQueue) Pop() any
Pop pops an item from the priority queue
func (*PriorityQueue) Push ¶
func (pq *PriorityQueue) Push(x any)
Push pushes an item onto the priority queue
func (*PriorityQueue) Remove ¶
func (pq *PriorityQueue) Remove(key string)
Remove removes items from the priority queue given the keys
func (PriorityQueue) Swap ¶
func (pq PriorityQueue) Swap(i, j int)
Swap swaps the items at index i and j
Click to show internal directories.
Click to hide internal directories.