Skip to content

Commit 350fa89

Browse files
committed
Add remove_opts to CacacheManager #111
1 parent 2325e6c commit 350fa89

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

http-cache/src/managers/cacache.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ use serde::{Deserialize, Serialize};
1111
pub struct CACacheManager {
1212
/// Directory where the cache will be stored.
1313
pub path: PathBuf,
14+
/// Options for removing cache entries.
15+
pub remove_opts: cacache::RemoveOpts,
1416
}
1517

1618
impl Default for CACacheManager {
1719
fn default() -> Self {
18-
Self { path: "./http-cacache".into() }
20+
Self {
21+
path: "./http-cacache".into(),
22+
remove_opts: cacache::RemoveOpts::new(),
23+
}
1924
}
2025
}
2126

@@ -27,6 +32,14 @@ struct Store {
2732

2833
#[allow(dead_code)]
2934
impl CACacheManager {
35+
/// Creates a new [`CACacheManager`] with the given path.
36+
pub fn new(path: PathBuf, remove_fully: bool) -> Self {
37+
Self {
38+
path,
39+
remove_opts: cacache::RemoveOpts::new().remove_fully(remove_fully),
40+
}
41+
}
42+
3043
/// Clears out the entire cache.
3144
pub async fn clear(&self) -> Result<()> {
3245
cacache::clear(&self.path).await?;
@@ -62,6 +75,7 @@ impl CacheManager for CACacheManager {
6275
}
6376

6477
async fn delete(&self, cache_key: &str) -> Result<()> {
65-
Ok(cacache::remove(&self.path, cache_key).await?)
78+
self.remove_opts.remove(&self.path, cache_key).await?;
79+
Ok(())
6680
}
6781
}

0 commit comments

Comments
 (0)