-
Notifications
You must be signed in to change notification settings - Fork 596
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
OnRemoveWithReason still receives deleted entry #126
Comments
@santatic are you saying the entry isn't actually being deleted? Can you explain the problem/question a bit more? |
Yes, that's my case. My steps:
|
Let me see if I can reproduce it with a test case and if I can, I'll get it fixed, if not I'll have to ask you for a reproduction so that we can ensure there are no regressions later. |
Here's the test that catches this case: diff --git a/bigcache_test.go b/bigcache_test.go
index 580777d..2444dd5 100644
--- a/bigcache_test.go
+++ b/bigcache_test.go
@@ -275,6 +275,55 @@ func TestOnRemoveFilter(t *testing.T) {
assert.True(t, onRemoveInvoked)
}
+func TestOnRemoveFilterExpired(t *testing.T) {
+ t.Parallel()
+
+ // given
+ clock := mockedClock{value: 0}
+ onDeleteInvoked := false
+ onExpireInvoked := false
+ onRemove := func(key string, entry []byte, reason RemoveReason) {
+ switch reason {
+ case Deleted:
+ onDeleteInvoked = true
+ case Expired:
+ onExpireInvoked = true
+ }
+ }
+
+ c := Config{
+ Shards: 1,
+ LifeWindow: 2 * time.Second,
+ CleanWindow: 1 * time.Second,
+ MaxEntriesInWindow: 1,
+ MaxEntrySize: 256,
+ OnRemoveWithReason: onRemove,
+ }.OnRemoveFilterSet(Expired)
+
+ cache, _ := newBigCache(c, &clock)
+
+ // when
+ cache.Set("key", []byte("value"))
+ clock.set(5)
+ cache.Delete("key")
+
+ // then
+ assert.False(t, onDeleteInvoked)
+ assert.True(t, onExpireInvoked, "onExpireInvoke is false, but wants true")
+
+ // reset value
+ onExpireInvoked = false
+
+ // when
+ cache.Set("key2", []byte("value2"))
+ cache.Delete("key2")
+ clock.set(5)
+
+ // then
+ assert.False(t, onDeleteInvoked)
+ assert.False(t, onExpireInvoked, "onExpireInvoke is true, but wants false")
+}
+
func TestCacheLen(t *testing.T) {
t.Parallel() It seems that |
Closed in #219. |
I deleted a key from cache,
OnRemoveWithReason
receives entry with reasonbigcache.Deleted
But then, at expire time
OnRemoveWithReason
still receives deleted entry with reasonbigcache.Expired
My config:
The text was updated successfully, but these errors were encountered: