From eedba1296840ad9b934a79f1f76fd42429a27d10 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 5 Jun 2026 16:46:36 +0200 Subject: [PATCH] bloblru: unexport add and get --- internal/bloblru/cache.go | 12 ++++++------ internal/bloblru/cache_test.go | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/internal/bloblru/cache.go b/internal/bloblru/cache.go index 9981f8a87..514e608ff 100644 --- a/internal/bloblru/cache.go +++ b/internal/bloblru/cache.go @@ -44,9 +44,9 @@ func New(size int) *Cache { return c } -// Add adds key id with value blob to c. +// add adds key id with value blob to c. // It may return an evicted buffer for reuse. -func (c *Cache) Add(id restic.ID, blob []byte) (old []byte) { +func (c *Cache) add(id restic.ID, blob []byte) (old []byte) { debug.Log("bloblru.Cache: add %v", id) size := cap(blob) + overhead @@ -77,7 +77,7 @@ func (c *Cache) Add(id restic.ID, blob []byte) (old []byte) { return old } -func (c *Cache) Get(id restic.ID) ([]byte, bool) { +func (c *Cache) get(id restic.ID) ([]byte, bool) { c.mu.Lock() blob, ok := c.c.Get(id) c.mu.Unlock() @@ -89,7 +89,7 @@ func (c *Cache) Get(id restic.ID) ([]byte, bool) { func (c *Cache) GetOrCompute(id restic.ID, compute func() ([]byte, error)) ([]byte, error) { // check if already cached - blob, ok := c.Get(id) + blob, ok := c.get(id) if ok { return blob, nil } @@ -124,7 +124,7 @@ func (c *Cache) GetOrCompute(id restic.ID, compute func() ([]byte, error)) ([]by // takes over, caches the computed value and cleans up its channel in c.inProgress. // Then goroutine A continues, does not detect a parallel computation and would try // to call compute() again. - blob, ok = c.Get(id) + blob, ok = c.get(id) if ok { return blob, nil } @@ -132,7 +132,7 @@ func (c *Cache) GetOrCompute(id restic.ID, compute func() ([]byte, error)) ([]by // download it blob, err := compute() if err == nil { - c.Add(id, blob) + c.add(id, blob) } return blob, err diff --git a/internal/bloblru/cache_test.go b/internal/bloblru/cache_test.go index d25daf764..5fe7bc73c 100644 --- a/internal/bloblru/cache_test.go +++ b/internal/bloblru/cache_test.go @@ -25,8 +25,8 @@ func TestCache(t *testing.T) { c := New(cacheSize) addAndCheck := func(id restic.ID, exp []byte) { - c.Add(id, exp) - blob, ok := c.Get(id) + c.add(id, exp) + blob, ok := c.get(id) rtest.Assert(t, ok, "blob %v added but not found in cache", id) rtest.Equals(t, &exp[0], &blob[0]) rtest.Equals(t, exp, blob) @@ -38,13 +38,13 @@ func TestCache(t *testing.T) { addAndCheck(id2, make([]byte, 1, 30*kiB)) addAndCheck(id3, make([]byte, 1, 10*kiB)) - _, ok := c.Get(id2) + _, ok := c.get(id2) rtest.Assert(t, ok, "blob %v not present", id2) - _, ok = c.Get(id1) + _, ok = c.get(id1) rtest.Assert(t, !ok, "blob %v present, but should have been evicted", id1) - c.Add(id1, make([]byte, 1+c.size)) - _, ok = c.Get(id1) + c.add(id1, make([]byte, 1+c.size)) + _, ok = c.get(id1) rtest.Assert(t, !ok, "blob %v too large but still added to cache") c.c.Remove(id1) @@ -141,6 +141,6 @@ func BenchmarkAdd(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - c.Add(ids[i%nblobs], buf[:sizes[i%nblobs]]) + c.add(ids[i%nblobs], buf[:sizes[i%nblobs]]) } }