Skip to content

Commit 50443cd

Browse files
authored
feat: expose cache_path for JsonBlockCacheDB (#42)
* expose cache_path for JsonBlockCacheDB * make fn const * use Path * use Option::as_deref
1 parent 421b292 commit 50443cd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/cache.rs

+20
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,11 @@ impl JsonBlockCacheDB {
465465

466466
trace!(target: "cache", "saved json cache");
467467
}
468+
469+
/// Returns the cache path.
470+
pub fn cache_path(&self) -> Option<&Path> {
471+
self.cache_path.as_deref()
472+
}
468473
}
469474

470475
/// The Data the [JsonBlockCacheDB] can read and flush
@@ -678,4 +683,19 @@ mod tests {
678683

679684
let _s = serde_json::to_string(&cache).unwrap();
680685
}
686+
687+
#[test]
688+
fn can_return_cache_path_if_set() {
689+
// set
690+
let cache_db = JsonBlockCacheDB::new(
691+
Arc::new(RwLock::new(BlockchainDbMeta::default())),
692+
Some(PathBuf::from("/tmp/foo")),
693+
);
694+
assert_eq!(Some(Path::new("/tmp/foo")), cache_db.cache_path());
695+
696+
// unset
697+
let cache_db =
698+
JsonBlockCacheDB::new(Arc::new(RwLock::new(BlockchainDbMeta::default())), None);
699+
assert_eq!(None, cache_db.cache_path());
700+
}
681701
}

0 commit comments

Comments
 (0)