Comments (3)
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.
from moka.
Thank you for reporting this issue.
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.
I started to work on this as #134 and made the Debug
impl to show some basic stats. But while I was writing a code sample for the doc, I realized this will confuse users as these stats are eventual consistent (will show stale numbers).
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 Debug
impl of std::collections::HashMap
does. It will be something like:
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 K
and V
must implement Debug
. I hope you are okay with this.
from moka.
Hi @lilyball — I have published Moka v0.8.5 to crates.io containing this and some other changes. Thanks!
from moka.
Related Issues (20)
- Statistics for metrics HOT 3
- `get_with` deadlock HOT 13
- `.blocking().invalidate(key)` doesn't trigger eviction listener HOT 1
- RUSTSEC-2020-0168: mach is unmaintained HOT 2
- Can the eviction strategy be configured? HOT 8
- Upgrade the cache policy from TinyLFU to W-TinyLFU
- Bump the MSRV to 1.60
- optionally_try_get_with in moka::future::Cache HOT 1
- feature request: remove method HOT 2
- Use `std::thread::available_parallelism()` instead of `num_cpus` dependency
- Eviction listener not always called. HOT 2
- Cache housekeeper can panic (seen after 50M+ insertions) HOT 4
- CI: Miri test causes a complie error with Rust nightly-2023-05-27 HOT 2
- Implement Serialize trait for debugging webserver? HOT 2
- Data race found by `miri test` HOT 9
- CI: Enable Miri tests on `moka::cht::*` modules
- Memory corruption observed when using Moka v0.9.6 HOT 15
- unbounded capacity? HOT 2
- Possibility of using async runtime tasks instead of thread pools HOT 10
- oom caused after use #234's statistics record code HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moka.