go-generics-cache icon indicating copy to clipboard operation
go-generics-cache copied to clipboard

Clock policy: Not show all the page with sequential access pattern

Open huiyuanWu opened this issue 1 year ago • 0 comments

Example test:

cache := clock.NewCache[int, int](clock.WithCapacity(10))
for i := 0; i < 10; i++ {
cache.Set(i, i)
}
cache.Set(10, 10)

if len(cache.Keys()) != 10 {
t.Errorf("want number of keys 10, but got %d, %v", len(cache.Keys()), cache.Keys())
}

When the cache is full, and new page is set, the hand will iterate through all the element in the cache and set referenceCount = 0. In that case, line 122 of clock.go failed to get the keys that is still in the page (but with ref count == 0).

huiyuanWu avatar Sep 20 '22 00:09 huiyuanWu