Skip to content
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 the invalidate_entries_if method #12

Merged
merged 35 commits into from
Jun 20, 2021
Merged

Conversation

tatsuya6502
Copy link
Member

@tatsuya6502 tatsuya6502 commented Mar 4, 2021

This PR adds the invalidate_entries_if method and supporting methods to all caches in Moka. invalidate_entries_if invalidates the entire cache based on a predicate on the key and value of each cache entry. This method was requested by #10.

Added

  • (API) Add invalidate_entries_if method to all cache implementations in Moka:
    • sync::Cache
    • sync::SegmentedCache
    • future::Cache
    • unsync::Cache
  • (API) Add support_invalidation_closures method to the following cache builders:
    • sync::CacheBuilder
    • future::CacheBuilder
    • Note that for these sync and future caches, this method must be called at the cache creation time as the cache needs to maintain additional internal data structures to support invalidate_entries_if method. Otherwise, calling invalidate_entries_if will return a PredicateError::InvalidationClosuresDisabled.
  • Add an internal invalidator module, containing a registry of invalidation predicates and a background invalidator (eviction) task.
  • Implement Iterator on internal Deque.

Changed

  • Update internal base_cache::Inner to run a new invalidate_entries method periodically.
  • Update get method in sync and future caches to check if an entry has been invalidated.
  • Lightly refactor test related methods on caches.

Fixes #10.

- Create invalidator module.
- Add thiserror crate to the dependencies.
- Implement iterator for deque.
Implementing background invalidation task.
- Implementing background invalidation task.
- Add the following trait bounds to the generic parameters of sync and
  future caches:
    - K: Send + Sync + 'static
    - V: 'static
    - S: Send + 'static
- Implementing background invalidation task.
- Add Send + Sync bounds to a generic parameter V of sync and future
  caches, so K, V and S have the following bounds:
    - K: Send + Sync + 'static
    - V: Send + Sync + 'static
    - S: Send + 'static
- Remove finished predicates after a invalidation scan.
- Simplify the implementation of Predicate
- Refactoring on the background invalidation task.
- Add Sync bounds to a generic parameter S of sync and future caches,
    so now all K, V and S have the following bounds:
    - Send + Sync + 'static
- Add the invalidate_entries_if method to the future cache.
- Add the support_invalidation_closures method to the builders in sync and
  future modules.
- Update the get methods in sync and future caches to check if the entry
  has been invalidated.
- Add invalidate_entries_if to the unsync cache.
- Simplify the implementation of invalidate_entries_if in the
  unsync cache.
Conflicts:
    CHANGELOG.md
    Cargo.toml
- Add dependency to uuid crate and change the predicate ID type from u64 to
  PredicateId, which is String of UUID version 4.
- Remove NoSpaceLeft variant from PredicateError as UUID collision will
  extreamly unlikely happens.
- Rename PredicateRegistrationError to PredicateError.
- Upgrade Quanta crate version from v0.7.1 to v0.8.0.
- Write docs for PredicateId and PredicateError.
- Brush up the docs for unsync::Cache::invalidate_entries_if.
Conflicts:
    CHANGELOG.md
    src/sync/base_cache.rs
    src/sync/cache.rs
- Rename CacheBuilder::enable_invalidation_with_closures to
  support_invalidation_closures.
- Remove an unused field from Invalidator.
- Implement `invalidate_entries_if` on `sync::SegmentedCache`.
- Optimize `base_cache::Inner::submit_invalidation_task` method for
  a case when the write order queue is empty.
- Refactor some cache methods for refactoring.
Fix a deadlock issue for dropping sync/future cache while running background
invalidation task.
@tatsuya6502 tatsuya6502 marked this pull request as ready for review June 20, 2021 06:32
Copy link
Member Author

@tatsuya6502 tatsuya6502 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging.

@tatsuya6502 tatsuya6502 merged commit 56ba3f0 into master Jun 20, 2021
@tatsuya6502 tatsuya6502 deleted the invalidate-entries-if branch June 20, 2021 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to invalidate the entire cache?
1 participant