Hey, I encountered an issue where RemovalListener callback is called with the new value instead of the one that was expired, this should not be happening am I correct?
Here is a simple test case
func TestCache(t *testing.T) {
ch := make(chan int)
dbCache := cache.New(
cache.WithRemovalListener(func(k cache.Key, v cache.Value) {
// We are expecting a delete event to Server 0
// But this test fails because value is Server 1 not Server 0
assert.Equal(t, "Server 0", v.(string))
ch <- 1
}),
cache.WithExpireAfterAccess(200*time.Millisecond),
)
dbCache.Put("key", "Server 0")
// Wait for cache to expire.
time.Sleep(time.Millisecond * 200)
// cache should now be expired, meaning GetIfPresent should not return a value.
_, exists := dbCache.GetIfPresent("key")
assert.False(t, exists)
// Add a new value into the same key
dbCache.Put("key", "Server 1")
<-ch
}
Hey, I encountered an issue where RemovalListener callback is called with the new value instead of the one that was expired, this should not be happening am I correct?
Here is a simple test case