-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Bug in moka::future::Cache::invalidate_all
? Elements not being invalidated immediatelly.
#155
Comments
Thank you for reporting the bug. I was aware of it when I implemented 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 Because of this, 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. |
Thanks so much! |
Hi.
According to the documentation of
invalidate_all
:From this I surmised that, even though the actual removal of elements occurs in the background, they would be somehow marked as invalid, and as such a subsequent
get
would not see them.However, this does not seem to be happening. Here's a small minimal example that exemplefies this
This fails in the last line (the get returns
Some(1)
)Is this a bug or am I misreading the documentation?
The text was updated successfully, but these errors were encountered: