[VAULT-4034] Revert back to caching nil values (#13013)

* Revert "[VAULT-4034] Only cache non-nil values (#12993)"

This reverts commit 67e1ed06c7.

* Update sdk/physical/cache.go

Co-authored-by: Nick Cabatoff <ncabatoff@hashicorp.com>

Co-authored-by: Nick Cabatoff <ncabatoff@hashicorp.com>
This commit is contained in:
Pratyoy Mukhopadhyay 2021-11-02 12:00:37 -07:00 committed by GitHub
parent 98421bb68c
commit fa03adb718
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2 additions and 49 deletions

View File

@ -1,3 +0,0 @@
```release-note:bug
sdk/physical: Fix to only populate cache with non-nil values
```

View File

@ -184,10 +184,8 @@ func (c *Cache) Get(ctx context.Context, key string) (*Entry, error) {
return nil, err
}
if ent != nil {
// Cache the result
// Cache the result, even if nil
c.lru.Add(key, ent)
}
return ent, nil
}

View File

@ -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))
}
}