summaryrefslogtreecommitdiff
path: root/lib/containers
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-07-13 22:38:43 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-07-14 01:09:20 -0600
commit7153fc9379dd5910c688925ccd2e0a03b9551a6d (patch)
treed1fd8edb223c130cc12c0ef2af3c6ae5130afda5 /lib/containers
parent913acf193bfac666cec68e8c3fb13829a7a0c794 (diff)
Buffer FS IO
Diffstat (limited to 'lib/containers')
-rw-r--r--lib/containers/lru.go11
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)