diff --git a/car-mirror-benches/Cargo.toml b/car-mirror-benches/Cargo.toml index ba1c467..ccda826 100644 --- a/car-mirror-benches/Cargo.toml +++ b/car-mirror-benches/Cargo.toml @@ -10,7 +10,7 @@ anyhow = "1.0" async-std = { version = "1.11", features = ["attributes"] } async-trait = "0.1" bytes = "1.4.0" -car-mirror = { path = "../car-mirror", version = "0.1", features = ["test_utils"] } +car-mirror = { path = "../car-mirror", version = "0.1", features = ["test_utils", "quick_cache"] } libipld = "0.16.0" wnfs-common = "0.1.23" diff --git a/car-mirror/Cargo.toml b/car-mirror/Cargo.toml index 891c95b..7b8ed45 100644 --- a/car-mirror/Cargo.toml +++ b/car-mirror/Cargo.toml @@ -33,7 +33,7 @@ iroh-car = "0.3.0" libipld = "0.16.0" libipld-core = "0.16.0" proptest = { version = "1.1", optional = true } -quick_cache = "0.4.0" +quick_cache = { version = "0.4.0", optional = true } roaring-graphs = { version = "0.12", optional = true } serde = "1.0.183" serde_ipld_dagcbor = "0.4.0" @@ -53,6 +53,7 @@ test-strategy = "0.3" [features] default = [] test_utils = ["proptest", "roaring-graphs"] +quick_cache = ["dep:quick_cache"] [package.metadata.docs.rs] all-features = true diff --git a/car-mirror/src/traits.rs b/car-mirror/src/traits.rs index fe06f86..163eb53 100644 --- a/car-mirror/src/traits.rs +++ b/car-mirror/src/traits.rs @@ -11,8 +11,8 @@ use wnfs_common::BlockStore; /// At the moment, all caches are conceptually memoization tables, so you don't /// necessarily need to think about being careful about cache eviction. /// -/// See `InMemoryCache` for a `quick_cache`-based implementation, and -/// `NoCache` for disabling the cache. +/// See `InMemoryCache` for a `quick_cache`-based implementation +/// (enable the `quick-cache` feature), and `NoCache` for disabling the cache. #[async_trait(?Send)] pub trait Cache { /// This returns further references from the block referenced by given CID, @@ -51,11 +51,13 @@ pub trait Cache { /// A [quick-cache]-based implementation of a car mirror cache. /// /// [quick-cache]: https://github.com/arthurprs/quick-cache/ +#[cfg(feature = "quick_cache")] #[derive(Debug)] pub struct InMemoryCache { references: quick_cache::sync::Cache>, } +#[cfg(feature = "quick_cache")] impl InMemoryCache { /// Create a new in-memory cache that approximately holds /// cached references for `approx_capacity` CIDs. @@ -82,6 +84,7 @@ impl InMemoryCache { } } +#[cfg(feature = "quick_cache")] #[async_trait(?Send)] impl Cache for InMemoryCache { async fn get_references_cached(&self, cid: Cid) -> Result>> {