From fa03adb718db050b51d996d1afc6cbc066c456f5 Mon Sep 17 00:00:00 2001 From: Pratyoy Mukhopadhyay <35388175+pmmukh@users.noreply.github.com> Date: Tue, 2 Nov 2021 12:00:37 -0700 Subject: [PATCH] [VAULT-4034] Revert back to caching nil values (#13013) * Revert "[VAULT-4034] Only cache non-nil values (#12993)" This reverts commit 67e1ed06c7199856f8493f416df55f06603881c6. * Update sdk/physical/cache.go Co-authored-by: Nick Cabatoff Co-authored-by: Nick Cabatoff --- changelog/12993.txt | 3 --- sdk/physical/cache.go | 6 ++--- sdk/physical/inmem/cache_test.go | 42 -------------------------------- 3 files changed, 2 insertions(+), 49 deletions(-) delete mode 100644 changelog/12993.txt diff --git a/changelog/12993.txt b/changelog/12993.txt deleted file mode 100644 index 5e9068b7cf..0000000000 --- a/changelog/12993.txt +++ /dev/null @@ -1,3 +0,0 @@ -```release-note:bug -sdk/physical: Fix to only populate cache with non-nil values -``` \ No newline at end of file diff --git a/sdk/physical/cache.go b/sdk/physical/cache.go index d399cdae3c..ffac33189b 100644 --- a/sdk/physical/cache.go +++ b/sdk/physical/cache.go @@ -184,10 +184,8 @@ func (c *Cache) Get(ctx context.Context, key string) (*Entry, error) { return nil, err } - if ent != nil { - // Cache the result - c.lru.Add(key, ent) - } + // Cache the result, even if nil + c.lru.Add(key, ent) return ent, nil } diff --git a/sdk/physical/inmem/cache_test.go b/sdk/physical/inmem/cache_test.go index ec1b5bcde0..e6e6dabfe3 100644 --- a/sdk/physical/inmem/cache_test.go +++ b/sdk/physical/inmem/cache_test.go @@ -328,45 +328,3 @@ func TestCache_Refresh(t *testing.T) { t.Fatalf("expected value baz, got %s", string(r.Value)) } } - -// TestCache_UpdateFromStorage fetches a nil value from cache, updates -// the underlying storage and checks the cache value on a subsequent lookup -func TestCache_UpdateFromStorage(t *testing.T) { - logger := logging.NewVaultLogger(log.Debug) - - inm, err := NewInmem(nil, logger) - if err != nil { - t.Fatal(err) - } - cache := physical.NewCache(inm, 0, logger, &metrics.BlackholeSink{}) - cache.SetEnabled(true) - - ent := &physical.Entry{ - Key: "foo", - Value: []byte("bar"), - } - - // Read should return nil - out, err := cache.Get(context.Background(), "foo") - if err != nil { - t.Fatalf("err: %v", err) - } - if out != nil { - t.Fatalf("should not have key") - } - - // Add data to the underlying backend - inm.Put(context.Background(), ent) - - // Read should return data - out, err = cache.Get(context.Background(), "foo") - if err != nil { - t.Fatalf("err: %v", err) - } - if out == nil { - t.Fatalf("should have key") - } - if string(out.Value) != "bar" { - t.Fatalf("expected value bar, got %s", string(out.Value)) - } -}