From 03399a60079d31183bc9043c859d269c4a24fe05 Mon Sep 17 00:00:00 2001 From: jinjingroad Date: Tue, 24 Jun 2025 07:12:02 +0800 Subject: [PATCH] refactor: use the built-in max/min to simplify the code (#4781) Signed-off-by: jinjingroad --- store/cache/cache.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/store/cache/cache.go b/store/cache/cache.go index d1d68bded..06e9a3d92 100644 --- a/store/cache/cache.go +++ b/store/cache/cache.go @@ -251,10 +251,8 @@ func (c *Cache) cleanup() { // cleanupOldest removes the oldest items if we're over the max items. func (c *Cache) cleanupOldest() { - threshold := c.config.MaxItems / 5 // Remove 20% of max items at once - if threshold < 1 { - threshold = 1 - } + // Remove 20% of max items at once + threshold := max(c.config.MaxItems/5, 1) currentCount := atomic.LoadInt64(&c.itemCount)