Comments (3)
Thank you for reporting the bug. I was aware of it when I implemented invalidate_all
function, but I have never had a chance to fix it and then forgot.
I fixed the bug with #156, and will release Moka v0.8.6 after I finish running a pre-release testing.
The root cause of the bug was that a cache entry's last_modified
timestamp was not set to the current time when it was inserted to the cache. Instead, it was set to the time when the cache entry was properly admitted to the cache by a background thread called "housekeeper".
Because of this, invalidate_all
function was unable to invalidate cache entries inserted just before calling invalidate_all
.
You can confirm this behavior by modifying your reproducer code as the followings:
#[tokio::test]
async fn invalidate_all_without_sync() {
let cache = Cache::new(1024);
assert_eq!(cache.get(&0), None);
cache.insert(0, 1).await;
assert_eq!(cache.get(&0), Some(1));
// In Moka v0.8.5 or earlier, you can workaround the issue
// by doing one of the followings:
//
// - Call `cache.sync()` before invalidating.
// - `cache.sync()` will run pending housekeeping task,
// so the entry's `last_modified` will be set to the
// current time.
// - Or, wait some time for the housekeeping task to run.
// Note that `cache.sync()` can be a heavy operation so it is
// not recommended to call it very often.
use moka::sync::ConcurrentCacheExt;
cache.sync();
// The housekeeping task will run ~0.5 seconds after the cache
// creation. Then it will run with ~0.3 seconds interval if the
// cache is not receiving heavy writes.
//
// tokio::time::sleep(Duration::from_millis(520)).await;
cache.invalidate_all();
assert_eq!(cache.get(&0), None);
}
With the next release Moka v0.8.6 (that has the fix), you do not have to do the above workaround. I will let you know when I publish v0.8.6 to crates.io.
from moka.
Hi @bsdinis. I have published Moka v0.8.6 to crates.io with the fix. Thanks!
from moka.
Thanks so much!
from moka.
Related Issues (20)
- Cache with max capacity of zero should not cache anything
- Proposal: support insert key with expire time? HOT 16
- CI: Disable external CI services on temporary merge-queue branches?
- 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
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.