diff --git a/.vscode/settings.json b/.vscode/settings.json index f4809d6b..e05e0ee2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,20 +4,6 @@ "CARGO_TARGET_DIR": "target/ra" }, "cSpell.words": [ - "CLFU", - "Deque", - "Deques", - "Einziger", - "Eytan", - "Hasher", - "Kawano", - "MSRV", - "Moka", - "Ohad", - "RUSTFLAGS", - "Ristretto", - "Tatsuya", - "Upsert", "aarch", "actix", "ahash", @@ -29,7 +15,9 @@ "deqs", "Deque", "Deques", + "Einziger", "else's", + "Eytan", "getrandom", "Hasher", "Kawano", @@ -38,6 +26,7 @@ "MSRV", "nanos", "nocapture", + "Ohad", "peekable", "preds", "reqwest", diff --git a/Cargo.toml b/Cargo.toml index d680d37a..006f25ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ atomic64 = [] [dependencies] crossbeam-channel = "0.5" +crossbeam-utils = "0.8" moka-cht = "0.4.2" num_cpus = "1.13" once_cell = "1.7" diff --git a/src/future/builder.rs b/src/future/builder.rs index 23f60dcd..28b04b44 100644 --- a/src/future/builder.rs +++ b/src/future/builder.rs @@ -203,7 +203,6 @@ impl CacheBuilder { mod tests { use super::CacheBuilder; - use super::Cache; use std::time::Duration; #[tokio::test] @@ -237,7 +236,7 @@ mod tests { #[should_panic(expected = "time_to_live is longer than 1000 years")] async fn build_cache_too_long_ttl() { let thousand_years_secs: u64 = 1000 * 365 * 24 * 3600; - let builder: CacheBuilder> = CacheBuilder::new(100); + let builder: CacheBuilder = CacheBuilder::new(100); let duration = Duration::from_secs(thousand_years_secs); builder .time_to_live(duration + Duration::from_secs(1)) @@ -248,7 +247,7 @@ mod tests { #[should_panic(expected = "time_to_idle is longer than 1000 years")] async fn build_cache_too_long_tti() { let thousand_years_secs: u64 = 1000 * 365 * 24 * 3600; - let builder: CacheBuilder> = CacheBuilder::new(100); + let builder: CacheBuilder = CacheBuilder::new(100); let duration = Duration::from_secs(thousand_years_secs); builder .time_to_idle(duration + Duration::from_secs(1)) diff --git a/src/sync/base_cache.rs b/src/sync/base_cache.rs index 6d004995..b8ab1089 100644 --- a/src/sync/base_cache.rs +++ b/src/sync/base_cache.rs @@ -14,8 +14,8 @@ use crate::{ }, PredicateError, }; - use crossbeam_channel::{Receiver, Sender, TrySendError}; +use crossbeam_utils::atomic::AtomicCell; use parking_lot::{Mutex, RwLock}; use smallvec::SmallVec; use std::{ @@ -400,8 +400,8 @@ impl EntrySizeAndFrequency { } struct RawTimestamps { - last_accessed: Arc, - last_modified: Arc, + last_accessed: Arc, + last_modified: Arc, } impl RawTimestamps { @@ -432,7 +432,7 @@ type CacheEntry = (Arc, Arc>); pub(crate) struct Inner { max_capacity: Option, - weighted_size: AtomicU64, + weighted_size: AtomicCell, cache: CacheStore, build_hasher: S, deques: Mutex>, @@ -481,14 +481,14 @@ where // Ensure skt_capacity fits in a range of `128u32..=u32::MAX`. let skt_capacity = max_capacity - .map(|n| n.try_into().unwrap_or_default()) // Convert to u32. - .unwrap_or(u32::MAX) + .map(|n| n.try_into().unwrap_or(u32::MAX)) // Convert to u32. + .unwrap_or_default() .max(128); let frequency_sketch = FrequencySketch::with_capacity(skt_capacity); Self { max_capacity: max_capacity.map(|n| n as u64), - weighted_size: AtomicU64::default(), + weighted_size: AtomicCell::default(), cache, build_hasher, deques: Mutex::new(Deques::default()), @@ -657,7 +657,7 @@ where let mut calls = 0; let mut should_sync = true; - let current_ws = self.weighted_size.load(Ordering::Acquire); + let current_ws = self.weighted_size.load(); let mut ws = WeightedSize { size: current_ws, weigher: self.weigher.as_ref(), @@ -695,8 +695,8 @@ where } } - debug_assert_eq!(self.weighted_size.load(Ordering::Acquire), current_ws); - self.weighted_size.store(ws.size, Ordering::Release); + debug_assert_eq!(self.weighted_size.load(), current_ws); + self.weighted_size.store(ws.size); if should_sync { Some(SyncPace::Fast) @@ -1291,7 +1291,7 @@ mod tests { let ensure_sketch_len = |max_capacity, len, name| { let cache = BaseCache::::new( - max_capacity, + Some(max_capacity), None, RandomState::default(), None, diff --git a/src/sync/builder.rs b/src/sync/builder.rs index 00edbc8a..066bb34a 100644 --- a/src/sync/builder.rs +++ b/src/sync/builder.rs @@ -265,7 +265,6 @@ impl CacheBuilder { #[cfg(test)] mod tests { - use super::Cache; use super::CacheBuilder; use std::time::Duration; @@ -329,7 +328,7 @@ mod tests { #[should_panic(expected = "time_to_live is longer than 1000 years")] async fn build_cache_too_long_ttl() { let thousand_years_secs: u64 = 1000 * 365 * 24 * 3600; - let builder: CacheBuilder> = CacheBuilder::new(100); + let builder: CacheBuilder = CacheBuilder::new(100); let duration = Duration::from_secs(thousand_years_secs); builder .time_to_live(duration + Duration::from_secs(1)) @@ -340,7 +339,7 @@ mod tests { #[should_panic(expected = "time_to_idle is longer than 1000 years")] async fn build_cache_too_long_tti() { let thousand_years_secs: u64 = 1000 * 365 * 24 * 3600; - let builder: CacheBuilder> = CacheBuilder::new(100); + let builder: CacheBuilder = CacheBuilder::new(100); let duration = Duration::from_secs(thousand_years_secs); builder .time_to_idle(duration + Duration::from_secs(1)) diff --git a/src/unsync/builder.rs b/src/unsync/builder.rs index 034d3c38..ab05d9a0 100644 --- a/src/unsync/builder.rs +++ b/src/unsync/builder.rs @@ -170,7 +170,6 @@ impl CacheBuilder { #[cfg(test)] mod tests { - use super::Cache; use super::CacheBuilder; use std::time::Duration; @@ -204,7 +203,7 @@ mod tests { #[should_panic(expected = "time_to_live is longer than 1000 years")] async fn build_cache_too_long_ttl() { let thousand_years_secs: u64 = 1000 * 365 * 24 * 3600; - let builder: CacheBuilder> = CacheBuilder::new(100); + let builder: CacheBuilder = CacheBuilder::new(100); let duration = Duration::from_secs(thousand_years_secs); builder .time_to_live(duration + Duration::from_secs(1)) @@ -215,7 +214,7 @@ mod tests { #[should_panic(expected = "time_to_idle is longer than 1000 years")] async fn build_cache_too_long_tti() { let thousand_years_secs: u64 = 1000 * 365 * 24 * 3600; - let builder: CacheBuilder> = CacheBuilder::new(100); + let builder: CacheBuilder = CacheBuilder::new(100); let duration = Duration::from_secs(thousand_years_secs); builder .time_to_idle(duration + Duration::from_secs(1)) diff --git a/src/unsync/cache.rs b/src/unsync/cache.rs index cae88ff2..2a2d48a4 100644 --- a/src/unsync/cache.rs +++ b/src/unsync/cache.rs @@ -165,8 +165,8 @@ where // Ensure skt_capacity fits in a range of `128u32..=u32::MAX`. let skt_capacity = max_capacity - .map(|n| n.try_into().unwrap_or_default()) // Convert to u32. - .unwrap_or(u32::MAX) + .map(|n| n.try_into().unwrap_or(u32::MAX)) // Convert to u32. + .unwrap_or_default() .max(128); let frequency_sketch = FrequencySketch::with_capacity(skt_capacity); Self {