-
Notifications
You must be signed in to change notification settings - Fork 873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete expired items before setting #132
base: master
Are you sure you want to change the base?
Conversation
@patrickmn for your review 🙏 |
0293691
to
59cc448
Compare
Check if an item exists and it has expired before setting so that onEvicted is actually called. Fixes patrickmn#48. Add test and split func Use nanoseconds instead Call onEvicted if item existed before setting Call onEvicted if item.Expired
aee9b1a
to
38560f5
Compare
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 ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In cache.go
<#132 (comment)>:
> @@ -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
<#132 (comment)>,
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. |
Check if an item exists and it has expired before setting so that
onEvicted is actually called.
Fixes #48.