Skip to content
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

LFU: Deterministic eviction #32

Open
erwanor opened this issue May 1, 2018 · 0 comments
Open

LFU: Deterministic eviction #32

erwanor opened this issue May 1, 2018 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed LFU LFU module v2

Comments

@erwanor
Copy link
Owner

erwanor commented May 1, 2018

Consider an LFU cache with capacity=10 i.e:

gc, _ := gcache.New(10).LFU().Build()

We fill the cache:

for key := 0; key < 10; i++ {
    value := fmt.Sprintf("val%d", key)
    gc.Set(key, val)
}

Now that the cache is filled, the next call to Cache.Set should lead to the eviction of the Least-Frequently-Used entry. So far, so good.

When multiple entries share the same frequency (here all our entries have freq=0) we "pick" one at random. That is, the Cache.evict internal function will iterate over the internal map until we have evicted enough entries. Iterating over a map is done in a randomized order (per Golang maps semantics). We should explore whether that's a desirable behavior or if we should evict the least recent entry when everything else is equal.

Potential solution: Use a sorted map for the internal LFU maps.

@erwanor erwanor added enhancement New feature or request help wanted Extra attention is needed v2 LFU LFU module labels May 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed LFU LFU module v2
Projects
None yet
Development

No branches or pull requests

1 participant