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

[Feature Request] Expose current cache capacity #18

Open
GnomedDev opened this issue Nov 21, 2023 · 1 comment · May be fixed by #42
Open

[Feature Request] Expose current cache capacity #18

GnomedDev opened this issue Nov 21, 2023 · 1 comment · May be fixed by #42
Labels
enhancement New feature or request

Comments

@GnomedDev
Copy link
Contributor

I'm working on a crate called typesize, generating estimates of struct sizes. I want to write an implementation for mini-moka however the interface is quite opaque, and I can handle under-shooting by generating from the iterator, but I'm also missing the capacity which seems like a pretty simple request.

If the capacity could be exposed for both caches, that would be lovely.

@tatsuya6502
Copy link
Member

Hi. Thank you for the request. However, I am afraid that exposing HashMap/DashMap’s capacity is not enough to calculate the amount of memory that a Cache uses.

A mini-moka Cache consists of several data structures and the followings greatly contribute the memory usage.

  • A hash table (HashMap or DashMap) to store cached entries.
  • A doubly linked list to track recent accesses to cached entries.
  • If TTL (time to live) is configured, another doubly linked list is enabled to track the write order of cached entries.
  • A frequency sketch (LFU filter), which estimates popularities of every keys that has been accessed (no matter if cached or not).
  • Two mpmc channels to buffer recordings of read and write operations to cache.

Also, each cached entry has metadata attached to track their state. They contribute the memory usage too.

See the following moka (not mini-moka) issue for more info:

There is a plan to provide statistics information about a Cache, and we could use it to provide the memory sizes of these data structures. I am currently hospitalized, but when I get better, I will think further about this.

@tatsuya6502 tatsuya6502 added the enhancement New feature or request label Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants