mirror of
https://github.com/lukaszraczylo/graphql-monitoring-proxy.git
synced 2026-10-20 06:28:13 +00:00
perf(cache): sort-based eviction and consistent non-positive TTL handling
The count-based evictOldest used an O(n squared) selection sort with a candidate cap over an unordered map range, so it could evict the wrong entries. It now collects all entries and sorts by expiry, matching the memory-based evictor. A non-positive CACHE_TTL behaved differently per backend: the standard memory cache panicked, Redis stored a permanent key, and the LRU cache expired entries immediately. Each backend now clamps a non-positive TTL to a shared default at its Set boundary. The nil-logger fallback in the Redis wrapper now uses the constructor so it cannot panic.
This commit is contained in:
Vendored
+4
-1
@@ -16,7 +16,10 @@ type CacheWrapper struct {
|
||||
// NewCacheWrapper creates a new cache wrapper
|
||||
func NewCacheWrapper(config *RedisConfig, logger *libpack_logger.Logger) *CacheWrapper {
|
||||
if logger == nil {
|
||||
logger = &libpack_logger.Logger{}
|
||||
// Use the proper constructor, not a zero-value &Logger{} -- its
|
||||
// timeFormat field is a nil atomic.Pointer, so a zero-value Logger
|
||||
// panics on the first log call instead of degrading gracefully.
|
||||
logger = libpack_logger.New()
|
||||
}
|
||||
return &CacheWrapper{
|
||||
redis: config,
|
||||
|
||||
Reference in New Issue
Block a user