lru

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 3 Imported by: 1 module, 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 {
	// contains filtered or unexported fields
}

Cache is a thread-safe size-bounded LRU cache.

func New

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

New returns a new thread-safe LRU cache or panics if size <= 0. Use for caches sized by constants or validated config, where a zero size indicates a programmer error rather than a runtime condition.

func (*Cache[K, V]) Add

func (l *Cache[K, V]) Add(key K, value V) (evicted bool)

func (*Cache[K, V]) Get

func (l *Cache[K, V]) Get(key K) (V, bool)

func (*Cache[K, V]) Len

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

func (*Cache[K, V]) Purge

func (l *Cache[K, V]) Purge()

func (*Cache[K, V]) Remove

func (l *Cache[K, V]) Remove(key K) (present bool)

type SimpleCache

type SimpleCache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

SimpleCache is a non-thread-safe size-bounded LRU cache. Use when external synchronization is provided (e.g. single-goroutine ownership).

func NewSimple

func NewSimple[K comparable, V any](size int) *SimpleCache[K, V]

NewSimple returns a new non-thread-safe LRU cache or panics if size <= 0.

func (*SimpleCache[K, V]) Add

func (l *SimpleCache[K, V]) Add(key K, value V) (evicted bool)

func (*SimpleCache[K, V]) Get

func (l *SimpleCache[K, V]) Get(key K) (V, bool)

func (*SimpleCache[K, V]) Len

func (l *SimpleCache[K, V]) Len() int

func (*SimpleCache[K, V]) Purge

func (l *SimpleCache[K, V]) Purge()

func (*SimpleCache[K, V]) Remove

func (l *SimpleCache[K, V]) Remove(key K) (present bool)

Jump to

Keyboard shortcuts

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