Documentation
¶
Index ¶
- type Cache
- func (c *Cache[K, V]) Evict(count int) int
- func (c *Cache[K, V]) Get(key K) *V
- func (c *Cache[K, V]) GetFrequency(key K) int
- func (c *Cache[K, V]) Has(key K) bool
- func (c *Cache[K, V]) Keys() []K
- func (c *Cache[K, V]) Len() int
- func (c *Cache[K, V]) Peek(key K) *V
- func (c *Cache[K, V]) Purge()
- func (c *Cache[K, V]) Remove(key K) bool
- func (c *Cache[K, V]) Set(key K, value V)
- func (c *Cache[K, V]) TopK(k int) []K
- type Eviction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K comparable, V any] struct { // If len > UpperBound, cache will automatically evict // down to LowerBound. If either value is 0, this behavior // is disabled. UpperBound int LowerBound int EvictionChannel chan<- Eviction[K, V] // contains filtered or unexported fields }
func (*Cache[K, V]) Get ¶
func (c *Cache[K, V]) Get(key K) *V
Get retrieves the key's value if it exists, incrementing the frequency. It returns nil if there is no value for the given key.
func (*Cache[K, V]) GetFrequency ¶
GetFrequency returns the frequency count of the given key
func (*Cache[K, V]) Has ¶
Has checks if the cache contains the given key, without incrementing the frequency.
func (*Cache[K, V]) Peek ¶ added in v1.1.0
func (c *Cache[K, V]) Peek(key K) *V
Peek retrieves the key's value if it exists, without incrementing the frequency. It returns nil if there is no value for the given key.
type Eviction ¶
type Eviction[K comparable, V any] struct { Key K Value V }
Click to show internal directories.
Click to hide internal directories.