mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-08 23:57:01 +02:00
[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:
parent
98421bb68c
commit
fa03adb718
@ -1,3 +0,0 @@
|
||||
```release-note:bug
|
||||
sdk/physical: Fix to only populate cache with non-nil values
|
||||
```
|
@ -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
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user