From 5ea826f3b55914c914fd9b60e1d607d9c58591ec Mon Sep 17 00:00:00 2001 From: mchavez Date: Tue, 3 Sep 2024 16:01:00 -0600 Subject: [PATCH] Code review changes part 4 --- pkg/uhttp/dbcache.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/uhttp/dbcache.go b/pkg/uhttp/dbcache.go index 9b82fc3f0..69d36e67f 100644 --- a/pkg/uhttp/dbcache.go +++ b/pkg/uhttp/dbcache.go @@ -44,13 +44,16 @@ const ( failInsert = "Failed to insert response data into cache table" staticQuery = "UPDATE http_cache SET %s=(%s+1) WHERE key = ?" failScanResponse = "Failed to scan rows for cached response" + defaultWaitDuration = int64(60) // Default Cleanup interval, 60 seconds + cacheTTLThreshold = 60 + cacheTTLMultiplier = 5 ) func NewDBCache(ctx context.Context, cfg CacheConfig) (*DBCache, error) { var ( err error dc = &DBCache{ - waitDuration: int64(60), // Default Cleanup interval, 60 seconds + waitDuration: defaultWaitDuration, // Default Cleanup interval, 60 seconds } ) l := ctxzap.Extract(ctx) @@ -77,9 +80,9 @@ func NewDBCache(ctx context.Context, cfg CacheConfig) (*DBCache, error) { return &DBCache{}, err } - if !cfg.DisableCache { // cache is enabled - if cfg.CacheTTL > 60 { - dc.waitDuration = int64(cfg.CacheTTL * 5) // set as a fraction of the Cache TTL + if cfg.CacheTTL > 0 { + if cfg.CacheTTL > cacheTTLThreshold { + dc.waitDuration = int64(cfg.CacheTTL * cacheTTLMultiplier) // set as a fraction of the Cache TTL } dc.expirationTime = int64(cfg.CacheTTL) // cache expiration time