-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Cache
missing Debug
impl
#132
Comments
Thank you for reporting this issue.
I started to work on this as #134 and made the use moka::sync::Cache;
let cache = Cache::new(10);
// Insert entries.
cache.insert('n', "Netherland Dwarf");
cache.insert('l', "Lop Eared");
cache.insert('d', "Dutch");
// Ensure an entry exists.
assert_eq!(cache.get(&'l'), Some("Lop Eared"));
// Print a debug info. Note that this may print stale numbers.
// (e.g. `entry_count` can be `0` instead of `3`)
println!("{:?}", cache);
// -> Cache { max_capacity: Some(10), entry_count: 0, weighted_size: 0 }
// You can mitigate this by performing a `sync` first.
// Bring `ConcurrentCacheExt` trait to the scope so we can use `sync` method.
use moka::sync::ConcurrentCacheExt;
// Call `sync` to run pending internal tasks.
cache.sync();
// Now it will print the actual numbers.
println!("{:?}", cache);
// -> Cache { max_capacity: Some(10), entry_count: 3, weighted_size: 3 } These are kept eventual consistent to improve performance (doc). So I think I will change it to show key-value entries like the use moka::sync::Cache;
let cache = Cache::new(10);
// Insert entries.
cache.insert('n', "Netherland Dwarf");
cache.insert('l', "Lop Eared");
cache.insert('d', "Dutch");
// Print a debug info.
println!("{:?}", cache);
// -> {'l': "Lop Eared", 'd': "Dutch", 'n': "Netherland Dwarf"}
// Note that entries are returned in arbitrary order. This will never show stale values, so it will not confuse users. To show key-value entries, both |
If it's easy enough to show those and won't be too expensive then that sounds fine to me. It just bothered me that my type that has a cache couldn't show anything at all about it. It looks like #134 is adding methods to query for these stats, which I appreciate as it means I have the option of showing those after all if it suits my usage better. |
Hi @lilyball — I have published Moka v0.8.5 to crates.io containing this and some other changes. Thanks! |
The
Cache
types are all missingDebug
impls, which is annoying. I'm not sure what offhand such an impl should show, but perhaps some basic stats about the cache if that's easy to gather.The text was updated successfully, but these errors were encountered: