arc

package module
v2.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: MPL-2.0 Imports: 2 Imported by: 47

Documentation

Index

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

func (c *ARCCache[K, V]) Contains(key K) bool

Contains is used to check if the cache contains a key without updating recency or frequency.

func (*ARCCache[K, V]) Get

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

Get looks up a key's value from the cache.

func (*ARCCache[K, V]) Keys

func (c *ARCCache[K, V]) Keys() []K

Keys returns all the cached keys

func (*ARCCache[K, V]) Len

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

Len returns the number of cached entries

func (*ARCCache[K, V]) Peek

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

Peek is used to inspect the cache value of a key without updating recency or frequency.

func (*ARCCache[K, V]) Purge

func (c *ARCCache[K, V]) Purge()

Purge is used to clear the cache

func (*ARCCache[K, V]) Remove

func (c *ARCCache[K, V]) Remove(key K)

Remove is used to purge a key from the cache

func (*ARCCache[K, V]) Values

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

Values returns all the cached values

Jump to

Keyboard shortcuts

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