Skip to content

Commit

Permalink
Implement the invalidate_entries_if method (WIP)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
tatsuya6502 committed May 5, 2021
1 parent b5aeb6e commit 49b914f
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 148 deletions.
2 changes: 1 addition & 1 deletion src/future/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ where
/// Builds a `Cache<K, V, S>`, with the given `hasher`.
pub fn build_with_hasher<S>(self, hasher: S) -> Cache<K, V, S>
where
S: BuildHasher + Clone + Send + 'static,
S: BuildHasher + Clone + Send + Sync + 'static,
{
Cache::with_everything(
self.max_capacity,
Expand Down
8 changes: 4 additions & 4 deletions src/future/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl<K, V, S> Cache<K, V, S>
where
K: Hash + Eq + Send + Sync + 'static,
V: Clone + Send + Sync + 'static,
S: BuildHasher + Clone + Send + 'static,
S: BuildHasher + Clone + Send + Sync + 'static,
{
pub(crate) fn with_everything(
max_capacity: usize,
Expand Down Expand Up @@ -368,7 +368,7 @@ impl<K, V, S> ConcurrentCacheExt<K, V> for Cache<K, V, S>
where
K: Hash + Eq + Send + Sync + 'static,
V: Send + Sync + 'static,
S: BuildHasher + Clone + Send + 'static,
S: BuildHasher + Clone + Send + Sync + 'static,
{
fn sync(&self) {
self.base.inner.sync(MAX_SYNC_REPEATS);
Expand All @@ -380,7 +380,7 @@ impl<K, V, S> Cache<K, V, S>
where
K: Hash + Eq + Send + Sync + 'static,
V: Clone + Send + Sync + 'static,
S: BuildHasher + Clone + Send + 'static,
S: BuildHasher + Clone + Send + Sync + 'static,
{
async fn insert_with_hash(&self, key: K, hash: u64, value: V) {
let op = self.base.do_insert_with_hash(key, hash, value);
Expand Down Expand Up @@ -447,7 +447,7 @@ impl<K, V, S> Cache<K, V, S>
where
K: Hash + Eq + Send + Sync + 'static,
V: Send + Sync + 'static,
S: BuildHasher + Clone + Send + 'static,
S: BuildHasher + Clone + Send + Sync + 'static,
{
fn reconfigure_for_testing(&mut self) {
self.base.reconfigure_for_testing();
Expand Down
10 changes: 5 additions & 5 deletions src/sync/base_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<K, V, S> BaseCache<K, V, S>
where
K: Hash + Eq + Send + Sync + 'static,
V: Clone + Send + Sync + 'static,
S: BuildHasher + Clone + Send + 'static,
S: BuildHasher + Clone + Send + Sync + 'static,
{
pub(crate) fn new(
max_capacity: usize,
Expand Down Expand Up @@ -211,7 +211,7 @@ impl<K, V, S> BaseCache<K, V, S>
where
K: Hash + Eq + Send + Sync + 'static,
V: Clone + Send + Sync + 'static,
S: BuildHasher + Clone + Send + 'static,
S: BuildHasher + Clone + Send + Sync + 'static,
{
#[inline]
fn record_read_op(&self, op: ReadOp<K, V>) -> Result<(), TrySendError<ReadOp<K, V>>> {
Expand Down Expand Up @@ -314,7 +314,7 @@ impl<K, V, S> BaseCache<K, V, S>
where
K: Hash + Eq + Send + Sync + 'static,
V: Send + Sync + 'static,
S: BuildHasher + Clone + Send + 'static,
S: BuildHasher + Clone + Send + Sync + 'static,
{
pub(crate) fn is_empty(&self) -> bool {
self.inner.len() == 0
Expand Down Expand Up @@ -519,7 +519,7 @@ impl<K, V, S> InnerSync for Inner<K, V, S>
where
K: Hash + Eq + Send + Sync + 'static,
V: Send + Sync + 'static,
S: BuildHasher + Clone + Send + 'static,
S: BuildHasher + Clone + Send + Sync + 'static,
{
fn sync(&self, max_repeats: usize) -> Option<SyncPace> {
const EVICTION_BATCH_SIZE: usize = 500;
Expand Down Expand Up @@ -573,7 +573,7 @@ impl<K, V, S> Inner<K, V, S>
where
K: Hash + Eq + Send + Sync + 'static,
V: Send + Sync + 'static,
S: BuildHasher + Clone + Send + 'static,
S: BuildHasher + Clone + Send + Sync + 'static,
{
fn apply_reads(&self, deqs: &mut Deques<K>, count: usize) {
use ReadOp::*;
Expand Down
4 changes: 2 additions & 2 deletions src/sync/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ where
/// calling this method.
pub fn build_with_hasher<S>(self, hasher: S) -> Cache<K, V, S>
where
S: BuildHasher + Clone + Send + 'static,
S: BuildHasher + Clone + Send + Sync + 'static,
{
Cache::with_everything(
self.max_capacity,
Expand Down Expand Up @@ -143,7 +143,7 @@ where
/// calling this method.
pub fn build_with_hasher<S>(self, hasher: S) -> SegmentedCache<K, V, S>
where
S: BuildHasher + Clone + Send + 'static,
S: BuildHasher + Clone + Send + Sync + 'static,
{
SegmentedCache::with_everything(
self.max_capacity,
Expand Down
8 changes: 4 additions & 4 deletions src/sync/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl<K, V, S> Cache<K, V, S>
where
K: Hash + Eq + Send + Sync + 'static,
V: Clone + Send + Sync + 'static,
S: BuildHasher + Clone + Send + 'static,
S: BuildHasher + Clone + Send + Sync + 'static,
{
pub(crate) fn with_everything(
max_capacity: usize,
Expand Down Expand Up @@ -331,7 +331,7 @@ impl<K, V, S> ConcurrentCacheExt<K, V> for Cache<K, V, S>
where
K: Hash + Eq + Send + Sync + 'static,
V: Send + Sync + 'static,
S: BuildHasher + Clone + Send + 'static,
S: BuildHasher + Clone + Send + Sync + 'static,
{
fn sync(&self) {
self.base.inner.sync(MAX_SYNC_REPEATS);
Expand All @@ -343,7 +343,7 @@ impl<K, V, S> Cache<K, V, S>
where
K: Hash + Eq + Send + Sync + 'static,
V: Clone + Send + Sync + 'static,
S: BuildHasher + Clone + Send + 'static,
S: BuildHasher + Clone + Send + Sync + 'static,
{
#[inline]
fn schedule_write_op(
Expand Down Expand Up @@ -378,7 +378,7 @@ impl<K, V, S> Cache<K, V, S>
where
K: Hash + Eq + Send + Sync + 'static,
V: Send + Sync + 'static,
S: BuildHasher + Clone + Send + 'static,
S: BuildHasher + Clone + Send + Sync + 'static,
{
pub(crate) fn reconfigure_for_testing(&mut self) {
self.base.reconfigure_for_testing();
Expand Down

0 comments on commit 49b914f

Please sign in to comment.