From ba4bb09f3e907767632eabf1d785b2ea90589eee Mon Sep 17 00:00:00 2001 From: Vikash Singh Date: Tue, 18 Jul 2023 12:45:45 +0530 Subject: [PATCH] add config for cleanup ticker duration --- cache.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cache.go b/cache.go index 93008cee..2b9a1d51 100644 --- a/cache.go +++ b/cache.go @@ -135,6 +135,8 @@ type Config struct { // cost passed to set is not using bytes as units. Keep in mind that setting // this to true will increase the memory usage. IgnoreInternalCost bool + // TtlTickerDurationInSec set the value of time ticker for cleanup keys on ttl + TtlTickerDurationInSec int64 } type itemFlag byte @@ -165,6 +167,8 @@ func NewCache(config *Config) (*Cache, error) { return nil, errors.New("MaxCost can't be zero") case config.BufferItems == 0: return nil, errors.New("BufferItems can't be zero") + case config.TtlTickerDurationInSec == 0: + config.TtlTickerDurationInSec = bucketDurationSecs } policy := newPolicy(config.NumCounters, config.MaxCost) cache := &Cache{ @@ -176,7 +180,7 @@ func NewCache(config *Config) (*Cache, error) { stop: make(chan struct{}), cost: config.Cost, ignoreInternalCost: config.IgnoreInternalCost, - cleanupTicker: time.NewTicker(time.Duration(bucketDurationSecs) * time.Second / 2), + cleanupTicker: time.NewTicker(time.Duration(config.TtlTickerDurationInSec) * time.Second / 2), } cache.onExit = func(val interface{}) { if config.OnExit != nil && val != nil {