diff options
Diffstat (limited to 'lib/containers')
-rw-r--r-- | lib/containers/lru.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/containers/lru.go b/lib/containers/lru.go index 8b8eb0e..a235a12 100644 --- a/lib/containers/lru.go +++ b/lib/containers/lru.go @@ -10,11 +10,22 @@ import ( lru "github.com/hashicorp/golang-lru" ) +// LRUCache is a least-recently-used(ish) cache. A zero LRUCache is +// usable and has a cache size of 128 items; use NewLRUCache to set a +// different size. type LRUCache[K comparable, V any] struct { initOnce sync.Once inner *lru.ARCCache } +func NewLRUCache[K comparable, V any](size int) *LRUCache[K, V] { + c := new(LRUCache[K, V]) + c.initOnce.Do(func() { + c.inner, _ = lru.NewARC(size) + }) + return c +} + func (c *LRUCache[K, V]) init() { c.initOnce.Do(func() { c.inner, _ = lru.NewARC(128) |