From 1a1d7b80760e09579f3b8740cf4765eb2983c018 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 17 Feb 2021 13:49:02 +0000 Subject: [PATCH] Keep the remaining 10% of cached entries --- internal/caching/impl_inmemorylru.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/caching/impl_inmemorylru.go b/internal/caching/impl_inmemorylru.go index 44e38fd3d..f0915d7ca 100644 --- a/internal/caching/impl_inmemorylru.go +++ b/internal/caching/impl_inmemorylru.go @@ -93,7 +93,12 @@ func cacheCleaner(caches ...*InMemoryLRUCachePartition) { for { time.Sleep(time.Minute) for _, cache := range caches { - cache.lru.RemoveOldest() + // 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() + } } } }