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

Freecache description #56

Closed
mangalaman93 opened this issue Feb 27, 2019 · 1 comment
Closed

Freecache description #56

mangalaman93 opened this issue Feb 27, 2019 · 1 comment

Comments

@mangalaman93
Copy link

We are working on an article about the current state of concurrent cache implementations in Go. We are planning to include freecache with following short description. Please let me know if my understanding is correct, or you would like to modify it.

FreeCache divides the cache into 256 segments. Each segment contains 256 slots
and a ring buffer to store the data. When a new key is added to the cache,
segment id is identified using the lower 8 bit of the hash of the key. Further,
slot is chosen using the LSB 9 to LSB 16 of the hash of the key. Dividing data into
slots helps in reducing the search space while looking for a key in the cache.

The data is then appended into the ring buffer and offset is stored into a sorted array.
If ring buffer doesn't have enough space, eviction is performed in the segment
from the beginning of the ring buffer using a modified LRU policy. An entry is
deleted from the ring buffer if the last access time for the entry is smaller
than the average access time of the segment. To find an entry in a cache on Get,
a binary search is performed in the sorted array in the corresponding slot.
@coocood
Copy link
Owner

coocood commented Feb 27, 2019

Yes, your understanding is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants