-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
Add support for eviction listener #145
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(WIP) Add support for notification on eviction to the following caches: - `sync::Cache` - `sync::SegmentedCache` - `future::Cache` Details: - Add `eviction_listener` method to the cache builders. - Add `notification` module with `RemovalCause` enum. - Add internal `sync_base::removal_notifier` module. - Implement some of the notifications. - Add a unit test case to `sync::Cache` for the implemented notifications.
Enable `RemovalCause::Replaced` events.
Tweak an unit test.
- Enable `RemovalCause::Expired` events. - Update existing unit test cases to verify the notifications after invalidating, replacing, evicting and expiring entries. - Update the README.
- Fix the `RemovalCause` for entries removed by `invalidate_all`.
- Add unit tests to `sync::SegmentedCache`.
- Add unit tests to `future::Cache`.
- Docs: Write code examples for eviction listener. - Update the dev dependencies: - Tokio v1.16 -> v1.18. - Add anyhow v1.0.
Fix a doc test (compile error).
Fix a bug with timing issues that causes to report wrong `RemovalCause` `Replaced` or `Explicit` when `Expired` is appropriate.
Implement basic part of blocking notifications.
Implement the rest of the part of blocking notifications but only to `sync::{Cache, SegmentedCache}`. (Will remove blocking mode from `future::Cache`) - Add `KeyLockMap` for locking a key during updating/removing its entry and processing a blocking notification. - Update the unit tests in `sync::Cache` to test blocking notifications.
to ensure `triomphe::Arc::count` function exists
Remove the second parameter `mode` from `future::CacheBuilder::eviction_listener` method as `future::Cache` will not support blocking notification mode in the coming release.
Conflicts: Cargo.toml
- Add `notification::Configuration` struct. - Add `eviction_listener_with_conf` method to `sync::Builder`. - Rename `notification::EvictionNotificationMode` enum to `notification::DeliveryMode`. - Update unit tests for `sync` caches to test both two `DeliveryMode` variants.
Rename `DeliveryMode::Direct` to `DeliveryMode::Immediate`.
Try to stabilize flaky tests caused by slow QEMU VMs.
Try to stabilize flaky tests caused by slow QEMU VMs.
Add an unit test to ensure the key-level lock is working.
Avoid the housekeeper and non-blocking notifier threads from stalling when the notification channel is full.
Tweak the name of an unit test and its code comments.
Add panic handling to the notifiers. When the user-provided listener panics, the notifier will no longer call the listener for safely.
Add unit tests for testing recovery from panicking eviction listener.
Emit an error log when the user provided eviction listener panics. (Requires `logging` feature enabled)
tatsuya6502
force-pushed
the
eviction-listener
branch
from
July 2, 2022 10:19
0ee3005
to
b97f622
Compare
- Rename the `eviction_listener` method of `future::CacheBuilder` to `eviction_listener_with_queued_delivery_mode`. - Write the documentation.
Add the `name` method to `sync` and `future` caches.
Write the documentation.
Rename `sync_base::removal_notifier` module to `notification::notifier`.
Write the documentation.
Fix "unused field" warnings in `notification::notifier` module.
Fix some typos in the documentation.
Remove unused function and struct.
tatsuya6502
commented
Jul 4, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merging.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a support for the eviction listener to the following caches:
sync::Cache
sync::SegmentedCache
future::Cache
The eviction listener is a closure with the following signature and can be used (for example) to keep other data structures in-sync with the cache.
and the enum
RemovalCause
(moka::notification::RemovalCause
) is defined as the followings:The enum
DeliveryMode
specifies how and when an eviction notification should be delivered to an eviction listener.Currently,
sync
caches support both modes andImmediate
mode is the default. Butfuture
cache supports onlyQueued
mode.Fixes #128