Skip to content

Commit 7f0be90

Browse files
committed
Add remove_opts to CacacheManager #111
1 parent 2325e6c commit 7f0be90

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

http-cache/src/managers/cacache.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ use http_cache_semantics::CachePolicy;
66
use serde::{Deserialize, Serialize};
77

88
/// Implements [`CacheManager`] with [`cacache`](https://github.com/zkat/cacache-rs) as the backend.
9-
#[cfg_attr(docsrs, doc(cfg(feature = "manager-cacache")))]
10-
#[derive(Debug, Clone)]
9+
#[derive(Clone)]
1110
pub struct CACacheManager {
1211
/// Directory where the cache will be stored.
1312
pub path: PathBuf,
13+
/// Options for removing cache entries.
14+
pub remove_opts: cacache::RemoveOpts,
1415
}
1516

16-
impl Default for CACacheManager {
17-
fn default() -> Self {
18-
Self { path: "./http-cacache".into() }
17+
impl std::fmt::Debug for CACacheManager {
18+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19+
f.debug_struct("CACacheManager").field("path", &self.path).finish()
1920
}
2021
}
2122

@@ -27,6 +28,14 @@ struct Store {
2728

2829
#[allow(dead_code)]
2930
impl CACacheManager {
31+
/// Creates a new [`CACacheManager`] with the given path.
32+
pub fn new(path: PathBuf, remove_fully: bool) -> Self {
33+
Self {
34+
path,
35+
remove_opts: cacache::RemoveOpts::new().remove_fully(remove_fully),
36+
}
37+
}
38+
3039
/// Clears out the entire cache.
3140
pub async fn clear(&self) -> Result<()> {
3241
cacache::clear(&self.path).await?;
@@ -62,6 +71,7 @@ impl CacheManager for CACacheManager {
6271
}
6372

6473
async fn delete(&self, cache_key: &str) -> Result<()> {
65-
Ok(cacache::remove(&self.path, cache_key).await?)
74+
self.remove_opts.clone().remove(&self.path, cache_key).await?;
75+
Ok(())
6676
}
6777
}

0 commit comments

Comments
 (0)