Documentation
¶
Overview ¶
Package TLRU implements a basic in-memory TLRU cache.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶
type Cache[K comparable, V any] struct { // contains filtered or unexported fields }
Cache implements a time aware least-frequently-used cache structure. When the cache exceeds a given cost limit, the oldest chunks of data are discarded.
func New ¶
func New[K comparable, V any](cost Coster[V], costLimit int) *Cache[K, V]
New instantiates a ready-to-use LRU cache. It is safe for concurrent use. If cost is nil, a constant cost of 1 is assumed. Use -1 for costLimit to disable cost limiting.
func (*Cache[K, V]) Do ¶ added in v0.4.0
Do is a helper that retrieves a value from the cache, if it exists, and calls the provided function to compute the value if it does not.
The return signature omits deadline and exists for ergonomics.
func (*Cache[K, V]) Evict ¶
Evict removes all expired entries from the cache. Bear in mind Set and Delete will also evict entries, so most users should not call Evict directly.
Directories
¶
Path | Synopsis |
---|---|
internal
|
|
doublelist
Package doublelist implements a doubly-linked list.
|
Package doublelist implements a doubly-linked list. |