Skip to content

Commit 7cc8b94

Browse files
committed
cache: ensure new expiration is persisted
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
1 parent 96f6041 commit 7cc8b94

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

internal/cache/cache.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (c *cache) Delete(key string) {
132132
}
133133

134134
// Clear all items from the cache.
135-
// This reallocate the inderlying array holding the items,
135+
// This reallocates the underlying array holding the items,
136136
// so that the memory used by the items is reclaimed.
137137
func (c *cache) Clear() {
138138
c.mu.Lock()
@@ -163,11 +163,10 @@ func (c *cache) HasExpired(key string) bool {
163163
func (c *cache) SetExpiration(key string, expiration time.Duration) {
164164
c.mu.Lock()
165165
item, ok := c.Items[key]
166-
if !ok {
167-
c.mu.Unlock()
168-
return
166+
if ok {
167+
item.Expiration = time.Now().Add(expiration).UnixNano()
168+
c.Items[key] = item
169169
}
170-
item.Expiration = time.Now().Add(expiration).UnixNano()
171170
c.mu.Unlock()
172171
}
173172

0 commit comments

Comments
 (0)