From 7cc8b9414389236e6db7af86aaa4fe07491ac5f4 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Tue, 1 Aug 2023 17:22:14 +0200 Subject: [PATCH] cache: ensure new expiration is persisted Signed-off-by: Hidde Beydals --- internal/cache/cache.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/internal/cache/cache.go b/internal/cache/cache.go index 1c11f09d..6f8ee860 100644 --- a/internal/cache/cache.go +++ b/internal/cache/cache.go @@ -132,7 +132,7 @@ func (c *cache) Delete(key string) { } // Clear all items from the cache. -// This reallocate the inderlying array holding the items, +// This reallocates the underlying array holding the items, // so that the memory used by the items is reclaimed. func (c *cache) Clear() { c.mu.Lock() @@ -163,11 +163,10 @@ func (c *cache) HasExpired(key string) bool { func (c *cache) SetExpiration(key string, expiration time.Duration) { c.mu.Lock() item, ok := c.Items[key] - if !ok { - c.mu.Unlock() - return + if ok { + item.Expiration = time.Now().Add(expiration).UnixNano() + c.Items[key] = item } - item.Expiration = time.Now().Add(expiration).UnixNano() c.mu.Unlock() }