lru

package
v1.26.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 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 {
	// contains filtered or unexported fields
}

Cache is a simple LRU (Least Recently Used) cache implementation.

func NewCache

func NewCache[K comparable, V any](capacity int) *Cache[K, V]

NewCache creates a new LRU cache with the given capacity.

func (*Cache[K, V]) Add

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

Add adds a value to the cache. If the key already exists, it updates the value and moves it to the front. If the cache is at capacity, it evicts the least recently used item.

func (*Cache[K, V]) Get

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

Get retrieves a value from the cache. If found, it moves the item to the front (marking it as recently used) and returns (value, true). If not found, returns (zero value, false).

Jump to

Keyboard shortcuts

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