lru

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

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 New

func New[K comparable, V any](cap int) *Cache[K, V]

func (*Cache[K, V]) Evict

func (c *Cache[K, V]) Evict(count int) int

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

func (c *Cache[K, V]) GetFrequency(key K) int

GetFrequency returns the frequency count of the given key

func (*Cache[K, V]) Has

func (c *Cache[K, V]) Has(key K) bool

Has checks if the cache contains the given key, without incrementing the frequency.

func (*Cache[K, V]) Keys

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

Keys returns all the keys in the cache

func (*Cache[K, V]) Len

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

Len returns the length of the cache

func (*Cache[K, V]) Set

func (c *Cache[K, V]) Set(key K, value V)

Set sets given key-value in the cache. If the key-value already exists, it increases the frequency.

type Eviction

type Eviction[K comparable, V any] struct {
	Key   K
	Value V
}

Jump to

Keyboard shortcuts

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