Closed HoganEdwardChu closed 1 year ago
Might help with more info, but, by default, cache.Get
is designed to return expired items.
https://github.com/karlseguin/ccache#get
By returning expired items, CCache lets you decide if you want to serve stale content or not. For example, you might decide to serve up slightly stale content (< 30 seconds old) while re-fetching newer data in the background. You might also decide to serve up infinitely stale content if you're unable to get new data from your source.
So you can use the Expired()
or TTL()
(which would be negative).
thanks for reply @karlseguin
currently we do like this
func GetValueByCache(cache *ccache.Cache, orderNumber int) (..., bool) {
value := cache.Get(orderNumber)
if value != nil {
return value, true
}
return nil, false
}
and if this return boolean is false we do cache set. Set but what you mean is this right?
func GetValueByCache(cache *ccache.Cache, orderNumber int) (..., bool) {
value := cache.Get(orderNumber)
if value != nil && !value.Expired() {
return value, true
}
return nil, false
}
-> And this modification makes after expired, cache will not give old value.
Yes
Thanks~
Sometimes cache give old result even though ttl expires.
How can we solve this situation? Could you give me some help? We do default cache configuration @karlseguin