Skip to content

Commit

Permalink
fix(TTL): clear expiryMap when cache is cleared
Browse files Browse the repository at this point in the history
  • Loading branch information
Woutifier committed Sep 29, 2023
1 parent 6ac4106 commit c888d21
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (sm *shardedMap[V]) Clear(onEvict func(item *Item[V])) {
for i := uint64(0); i < numShards; i++ {
sm.shards[i].Clear(onEvict)
}
sm.expiryMap.clear()
}

type lockedMap[V any] struct {
Expand Down
13 changes: 13 additions & 0 deletions ttl.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,16 @@ func (m *expirationMap[V]) cleanup(store store[V], policy policy[V], onEvict fun
}
}
}

// clear clears the expirationMap, the caller is responsible for properly
// evicting the referenced items
func (m *expirationMap) clear() {
if m == nil {
return
}

m.Lock()
m.buckets = make(map[int64]bucket)
m.lastCleanedBucketNum = cleanupBucket(time.Now())
m.Unlock()
}

0 comments on commit c888d21

Please sign in to comment.