Keep the remaining 10% of cached entries

This commit is contained in:
Neil Alexander 2021-02-17 13:49:02 +00:00
parent 2b4162523f
commit 1a1d7b8076
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -93,9 +93,14 @@ func cacheCleaner(caches ...*InMemoryLRUCachePartition) {
for {
time.Sleep(time.Minute)
for _, cache := range caches {
// Hold onto the last 10% of the cache entries, since
// otherwise a quiet period might cause us to evict all
// cache entries entirely.
if cache.lru.Len() > cache.maxEntries/10 {
cache.lru.RemoveOldest()
}
}
}
}
type InMemoryLRUCachePartition struct {