Documentation ¶
Index ¶
- type ARCCache
- func (c *ARCCache[K, V]) Add(key K, value V)
- func (c *ARCCache[K, V]) Contains(key K) bool
- func (c *ARCCache[K, V]) Get(key K) (value V, ok bool)
- func (c *ARCCache[K, V]) Keys() []K
- func (c *ARCCache[K, V]) Len() int
- func (c *ARCCache[K, V]) Peek(key K) (value V, ok bool)
- func (c *ARCCache[K, V]) Purge()
- func (c *ARCCache[K, V]) Remove(key K)
- func (c *ARCCache[K, V]) Values() []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ARCCache ¶
type ARCCache[K comparable, V any] struct { // contains filtered or unexported fields }
ARCCache is a thread-safe fixed size Adaptive Replacement Cache (ARC). ARC is an enhancement over the standard LRU cache in that tracks both frequency and recency of use. This avoids a burst in access to new entries from evicting the frequently used older entries. It adds some additional tracking overhead to a standard LRU cache, computationally it is roughly 2x the cost, and the extra memory overhead is linear with the size of the cache. ARC has been patented by IBM, but is similar to the TwoQueueCache (2Q) which requires setting parameters.
func NewARC ¶
func NewARC[K comparable, V any](size int) (*ARCCache[K, V], error)
NewARC creates an ARC of the given size
func (*ARCCache[K, V]) Add ¶
func (c *ARCCache[K, V]) Add(key K, value V)
Add adds a value to the cache.
func (*ARCCache[K, V]) Contains ¶
Contains is used to check if the cache contains a key without updating recency or frequency.
func (*ARCCache[K, V]) Peek ¶
Peek is used to inspect the cache value of a key without updating recency or frequency.