lru

package
v0.0.0-...-5c6b87f Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

package lru provides a generic least-recently-used cache.

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 implements an LRU cache, with a particular maximum size.

func New

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

func (*Cache[K, V]) Add

func (c *Cache[K, V]) Add(k K, v V)

Add inserts an element into the cache, removing an element if necessary to keep the size fixed. If the key is already present its value is updated.

func (*Cache[K, V]) Get

func (c *Cache[K, V]) Get(k K) (v V, ok bool)

Get returns the value associated with the given key from the cache, as well as a boolean indicating whether the key was found. It also moves the accessed item to the front of the LRU list, indicating it was recently used.

Jump to

Keyboard shortcuts

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