jellydator / ttlcache

An in-memory cache with item expiration and generics
MIT License
930 stars 116 forks source link

Cache Never Expires Over Certain TTL Value #52

Closed ztroop closed 3 years ago

ztroop commented 3 years ago

I noticed while playing with this module that I can specify a TTL value from 10 to 50 seconds and everything works great! However, if I specify a TTL value like 300, the cache never seems to expire. Apologies of I'm missing something simple here!

Code Snippet:

cache := ttlcache.NewCache()
ttl, err := strconv.Atoi(cacheTTL)
if err != nil {
    log.Fatal("Invalid TTL value: ", err)
}
cache.SetTTL(time.Duration(ttl) * time.Second)

expirationCallback := func(key string, _ ttlcache.EvictionReason, _ interface{}) {
    log.Info("Cache expired for key: ", key)
}
cache.SetExpirationReasonCallback(expirationCallback)
jspri commented 3 years ago

Hey ztroop, you might need to look at the SkipTTLExtensionOnHit(bool) option.

ztroop commented 3 years ago

That appears to be what I needed, thanks for steering me in the right direction.

ReneKroon commented 3 years ago

Happy to see some community interaction! PROPS TO YOU, @jspri, once again.