Feature: lru cache add evict callback

This commit is contained in:
Dreamacro
2019-12-05 00:17:24 +08:00
parent 3e4bc9f85c
commit 93e0dbdc78
2 changed files with 35 additions and 0 deletions

View File

@ -115,3 +115,24 @@ func TestMaxSize(t *testing.T) {
_, ok = c.Get("foo")
assert.False(t, ok)
}
func TestExist(t *testing.T) {
c := NewLRUCache(WithSize(1))
c.Set(1, 2)
assert.True(t, c.Exist(1))
c.Set(2, 3)
assert.False(t, c.Exist(1))
}
func TestEvict(t *testing.T) {
temp := 0
evict := func(key interface{}, value interface{}) {
temp = key.(int) + value.(int)
}
c := NewLRUCache(WithEvict(evict), WithSize(1))
c.Set(1, 2)
c.Set(2, 3)
assert.Equal(t, temp, 3)
}