Skip to content

Commit 5bf60a6

Browse files
committed
Explicitly remove nonexistence sentinel on set
1 parent 8b49466 commit 5bf60a6

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

cache/cache.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ func (c *Cache[T]) set(ctx context.Context, key string, value T) error {
217217
return err
218218
}
219219

220+
// Remove any explicit nonexistence sentinel
221+
err = c.client.Del(ctx, keys.negative).Err()
222+
if err != nil {
223+
return err
224+
}
225+
220226
// Update cached value
221227
err = c.client.Set(ctx, keys.data, string(data), c.opts.Stale).Err()
222228
if err != nil {

cache/cache_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func (m mockWrapper) ExpectCacheFill(key string, value any) {
7272
if err != nil {
7373
panic(err)
7474
}
75+
m.ExpectDel("cache:negative:" + m.name + ":" + key).SetVal(0)
7576
m.ExpectSet("cache:data:"+m.name+":"+key, string(data), m.stale).SetVal("OK")
7677
m.ExpectSet("cache:fresh:"+m.name+":"+key, 1, m.fresh).SetVal("OK")
7778
}

0 commit comments

Comments
 (0)