Skip to content

Commit

Permalink
Merge pull request #500 from moka-rs/reorg-sync-base
Browse files Browse the repository at this point in the history
Refactoring: Reorganize directory structure
  • Loading branch information
tatsuya6502 authored Feb 23, 2025
2 parents e7c25b0 + 5e8c1d6 commit e970c84
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 37 deletions.
1 change: 1 addition & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub(crate) mod deque;
pub(crate) mod entry;
pub(crate) mod error;
pub(crate) mod frequency_sketch;
pub(crate) mod iter;
pub(crate) mod time;
pub(crate) mod timer_wheel;

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ pub trait FutureExt: Future {
/// Iterator visiting all key-value pairs in a cache in arbitrary order.
///
/// Call [`Cache::iter`](./struct.Cache.html#method.iter) method to obtain an `Iter`.
pub struct Iter<'i, K, V>(crate::sync_base::iter::Iter<'i, K, V>);
pub struct Iter<'i, K, V>(crate::common::iter::Iter<'i, K, V>);

impl<'i, K, V> Iter<'i, K, V> {
pub(crate) fn new(inner: crate::sync_base::iter::Iter<'i, K, V>) -> Self {
pub(crate) fn new(inner: crate::common::iter::Iter<'i, K, V>) -> Self {
Self(inner)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/future/base_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ use crate::{
},
deque::{DeqNode, Deque},
frequency_sketch::FrequencySketch,
iter::ScanningGet,
time::{AtomicInstant, Clock, Instant},
timer_wheel::{ReschedulingResult, TimerWheel},
CacheRegion, HousekeeperConfig,
},
future::CancelGuard,
notification::{AsyncEvictionListener, RemovalCause},
policy::{EvictionPolicy, EvictionPolicyConfig, ExpirationPolicy},
sync_base::iter::ScanningGet,
Entry, Expiry, Policy, PredicateError,
};

Expand Down
2 changes: 1 addition & 1 deletion src/future/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ where
/// ```
///
pub fn iter(&self) -> Iter<'_, K, V> {
use crate::sync_base::iter::{Iter as InnerIter, ScanningGet};
use crate::common::iter::{Iter as InnerIter, ScanningGet};

let inner = InnerIter::with_single_cache_segment(&self.base, self.base.num_cht_segments());
Iter::new(inner)
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,6 @@ pub mod ops;
#[cfg(any(feature = "sync", feature = "future"))]
pub mod policy;

#[cfg(any(feature = "sync", feature = "future"))]
pub(crate) mod sync_base;

#[cfg(any(feature = "sync", feature = "future"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "sync", feature = "future"))))]
pub use common::error::PredicateError;
Expand Down
15 changes: 14 additions & 1 deletion src/sync.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
//! Provides thread-safe, concurrent cache implementations.
mod base_cache;
mod builder;
mod cache;
mod entry_selector;
mod invalidator;
mod key_lock;
mod segment;
mod value_initializer;

pub use crate::sync_base::{iter::Iter, PredicateId};
/// The type of the unique ID to identify a predicate used by
/// [`Cache::invalidate_entries_if`][invalidate-if] method.
///
/// A `PredicateId` is a `String` of UUID (version 4).
///
/// [invalidate-if]: ./struct.Cache.html#method.invalidate_entries_if
pub type PredicateId = String;

pub(crate) type PredicateIdStr<'a> = &'a str;

pub use crate::common::iter::Iter;
pub use {
builder::CacheBuilder,
cache::Cache,
Expand Down
2 changes: 1 addition & 1 deletion src/sync_base/base_cache.rs → src/sync/base_cache.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::{
invalidator::{Invalidator, KeyDateLite, PredicateFun},
iter::ScanningGet,
key_lock::{KeyLock, KeyLockMap},
PredicateId,
};
Expand All @@ -21,6 +20,7 @@ use crate::{
},
deque::{DeqNode, Deque},
frequency_sketch::FrequencySketch,
iter::ScanningGet,
time::{AtomicInstant, Clock, Instant},
timer_wheel::{ReschedulingResult, TimerWheel},
CacheRegion, HousekeeperConfig,
Expand Down
6 changes: 2 additions & 4 deletions src/sync/cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::{
base_cache::{BaseCache, HouseKeeperArc},
value_initializer::{InitResult, ValueInitializer},
CacheBuilder, OwnedKeyEntrySelector, RefKeyEntrySelector,
};
Expand All @@ -7,17 +8,14 @@ use crate::{
concurrent::{
constants::WRITE_RETRY_INTERVAL_MICROS, housekeeper::InnerSync, Weigher, WriteOp,
},
iter::ScanningGet,
time::{Clock, Instant},
HousekeeperConfig,
},
notification::EvictionListener,
ops::compute::{self, CompResult},
policy::{EvictionPolicy, ExpirationPolicy},
sync::{Iter, PredicateId},
sync_base::{
base_cache::{BaseCache, HouseKeeperArc},
iter::ScanningGet,
},
Entry, Policy, PredicateError,
};

Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions src/sync/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ use super::{cache::Cache, CacheBuilder, OwnedKeyEntrySelector, RefKeyEntrySelect
use crate::common::concurrent::Weigher;
use crate::common::time::Clock;
use crate::{
common::HousekeeperConfig,
common::{
iter::{Iter, ScanningGet},
HousekeeperConfig,
},
notification::EvictionListener,
policy::{EvictionPolicy, ExpirationPolicy},
sync_base::iter::{Iter, ScanningGet},
Entry, Policy, PredicateError,
};

Expand Down
22 changes: 0 additions & 22 deletions src/sync_base.rs

This file was deleted.

0 comments on commit e970c84

Please sign in to comment.