mirror of
https://github.com/lukaszraczylo/graphql-monitoring-proxy.git
synced 2026-11-05 08:14:19 +00:00
fix(cache): enforce entry cap below ten in memory cache
The count-based eviction removed a tenth of the cap. For a cap under ten, that was zero entries, so the cache grew without limit. The cache now evicts at least one entry when it is full.
This commit is contained in:
Vendored
+2
-1
@@ -158,7 +158,8 @@ func (c *Cache) Set(key string, value []byte, ttl time.Duration) {
|
||||
c.evictToFreeMemory(memoryToFree)
|
||||
} else if atomic.LoadInt64(&c.entryCount) >= c.maxCacheSize {
|
||||
// Fall back to count-based eviction for backward compatibility
|
||||
c.evictOldest(int(c.maxCacheSize / 10)) // Evict 10% of entries
|
||||
// 10% of entries, at least one: max/10 is 0 for caps below 10.
|
||||
c.evictOldest(int(max(1, c.maxCacheSize/10)))
|
||||
}
|
||||
|
||||
// A non-positive TTL is clamped to defaultTTL so this backend expires
|
||||
|
||||
Reference in New Issue
Block a user