Documentation
¶
Overview ¶
Package lrucache is a small bounded cache keyed by string: least recently used entries are evicted at capacity, and a value that is missing is built once even when many goroutines ask for it at the same moment.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[V any] struct { // contains filtered or unexported fields }
Cache holds up to max values. The zero value is not usable; call New.
func (*Cache[V]) Add ¶
Add stores v under key, replacing any previous value, and drops the least recently used entries until the cache is within capacity.
func (*Cache[V]) Do ¶
Do returns the value for key, building and storing it with build when it is missing. Concurrent callers for the same missing key share one build; a build that fails stores nothing and every waiting caller sees the error.