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: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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