cache: ensure new expiration is persisted

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
This commit is contained in:
Hidde Beydals 2023-08-01 17:22:14 +02:00
parent 96f604118b
commit 7cc8b94143
No known key found for this signature in database
GPG Key ID: 979F380FC2341744
1 changed files with 4 additions and 5 deletions

View File

@ -132,7 +132,7 @@ func (c *cache) Delete(key string) {
} }
// Clear all items from the cache. // 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. // so that the memory used by the items is reclaimed.
func (c *cache) Clear() { func (c *cache) Clear() {
c.mu.Lock() c.mu.Lock()
@ -163,11 +163,10 @@ func (c *cache) HasExpired(key string) bool {
func (c *cache) SetExpiration(key string, expiration time.Duration) { func (c *cache) SetExpiration(key string, expiration time.Duration) {
c.mu.Lock() c.mu.Lock()
item, ok := c.Items[key] item, ok := c.Items[key]
if !ok { if ok {
c.mu.Unlock() item.Expiration = time.Now().Add(expiration).UnixNano()
return c.Items[key] = item
} }
item.Expiration = time.Now().Add(expiration).UnixNano()
c.mu.Unlock() c.mu.Unlock()
} }