cache

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 1 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 generic fixed-size LRU cache wrapping hashicorp/golang-lru/v2.

func NewCache

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

NewCache creates an LRU Cache with the given maximum size. A non-positive size returns an error from the underlying implementation.

func (*Cache[K, V]) Add

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

Add inserts or updates key with value, evicting the least-recently-used entry if the cache is full. It returns true if an eviction occurred.

func (*Cache[K, V]) Get

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

Get returns the value for key and reports whether it was present. Accessing a key marks it as most-recently-used.

func (*Cache[K, V]) Len

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

Len returns the number of entries currently in the cache.

func (*Cache[K, V]) Remove

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

Remove removes key from the cache. It returns true if key was present.

Jump to

Keyboard shortcuts

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