Documentation
¶
Overview ¶
Package lrucache implements a small bounded LRU cache safe for concurrent use. It exists so the enricher's per-process memoization caches (album → release-MBID, artist → MBID, etc.) have a hard size ceiling instead of growing for the lifetime of the process.
The cache is keyed by `comparable` and stores any value type. Map capacity is pre-allocated at construction so the bulk-ingestion phase of a 50k-track scan doesn't trigger Go map bucket resizing mid-flight; the doubly-linked list grows naturally.
We don't pull in `hashicorp/golang-lru` because the dependency surface isn't worth ~80 LOC of generics. Reads on empty buckets short-circuit cheaply.
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 bounded, mutex-protected LRU. Zero value is NOT usable — always construct via New.
func New ¶
func New[K comparable, V any](capacity int) *Cache[K, V]
New returns a Cache with the given capacity. Capacity <= 0 is silently treated as 1 — a zero-cap cache would never store anything, which is almost certainly a configuration bug we'd rather surface as "very small" than "silently broken".
func (*Cache[K, V]) Get ¶
Get returns the cached value and true on hit; the zero value and false on miss. A hit moves the entry to the front (most-recently- used).
func (*Cache[K, V]) Has ¶
Has returns true if key is present, without promoting it to MRU. Useful for negative-cache checks where the caller doesn't want the lookup itself to keep the entry alive.