go-generics-cache
go-generics-cache copied to clipboard
Clock policy: Not show all the page with sequential access pattern
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).