go-cache
go-cache copied to clipboard
Delete expired items before setting
Check if an item exists and it has expired before setting so that onEvicted is actually called.
Fixes #48.
@patrickmn for your review 🙏
No. Always.
We overwrite an existing item. It should be comparison tha the item that we overwrite is a different one. So, this comparison is deliberate. Usage of expired produces wrong behavior.
On Thu, 15 Oct 2020 at 01:58, Jaime Martinez [email protected] wrote:
@jaimem88 commented on this pull request.
In cache.go https://github.com/patrickmn/go-cache/pull/132#discussion_r505085507:
@@ -57,6 +57,10 @@ func (c *cache) Set(k string, x interface{}, d time.Duration) { if d > 0 { e = time.Now().Add(d).UnixNano() }
- // delete before setting and call onEvicted
- c.deleteIfExpired(k)
updated :)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/patrickmn/go-cache/pull/132#discussion_r505085507, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASOSQK3G7GDYXNVFTMGGCLSKY3KJANCNFSM4SNYEWEA .
@patrickmn Would you mind looking at this?
Note this is a incompatible change, and some people may be relying on the current behaviour.
Also this library doesn't seem maintained at the moment, so little chance it will get merged. It's better to just maintain your own fork if you need this behaviour.
Trying to find a cache with TTL that has been rigorously tested and this seems to be a popular choice. However, looks like repo is not maintained and hasn't been released since 2017. @koalalorenzo Where you able to find any other forks reliable?