refactor: use the built-in max/min to simplify the code (#4781)

Signed-off-by: jinjingroad <jinjingroad@sina.com>
This commit is contained in:
jinjingroad 2025-06-24 07:12:02 +08:00 committed by GitHub
parent e6e460493c
commit 03399a6007
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 4 deletions

View File

@ -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)