bloblru: unexport add and get

This commit is contained in:
Michael Eischer
2026-06-05 16:46:36 +02:00
parent 264cfbcff2
commit eedba12968
2 changed files with 13 additions and 13 deletions
+6 -6
View File
@@ -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
+7 -7
View File
@@ -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]])
}
}