Skip to content

Commit

Permalink
add hardcap for memory cache duration
Browse files Browse the repository at this point in the history
  • Loading branch information
Stumble committed Jan 31, 2023
1 parent 218181a commit b67fa25
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const (
maxReadInterval = 3 * time.Second
)

// Hardcap for memory cache TTL, changeable for testing.
var memCacheMaxTTLSeconds int64 = 5

// compression constants
const (
compressionThreshold = 64
Expand Down Expand Up @@ -372,6 +375,9 @@ func (c *DCache) updateMemoryCache(key string, ve *ValueBytesExpiredAt, isExplic
// update memory cache.
// sub-second TTL will be ignored for memory cache.
ttl := time.UnixMilli(ve.ExpiredAt).Unix() - getNow().Unix()
if ttl > memCacheMaxTTLSeconds {
ttl = memCacheMaxTTLSeconds
}
if c.inMemCache != nil && ttl > 0 {
memValue, err := c.inMemCache.Get([]byte(storeKey(key)))
// Broadcast invalidation request only when value is explicitly set to new one,
Expand Down

0 comments on commit b67fa25

Please sign in to comment.