pub struct ContentCache { /* private fields */ }Expand description
A content-addressed cache rooted at a directory.
Implementations§
Source§impl ContentCache
impl ContentCache
Sourcepub fn new(root: impl Into<PathBuf>) -> Result<Self>
pub fn new(root: impl Into<PathBuf>) -> Result<Self>
Creates a cache rooted at root, creating the directory if needed.
Sourcepub fn entry_path(&self, checksum: &Checksum) -> Result<PathBuf>
pub fn entry_path(&self, checksum: &Checksum) -> Result<PathBuf>
Returns the path an entry with checksum would use.
Sourcepub async fn lookup_verified(
&self,
checksum: &Checksum,
size: u64,
) -> Result<Option<PathBuf>>
pub async fn lookup_verified( &self, checksum: &Checksum, size: u64, ) -> Result<Option<PathBuf>>
Looks up an entry and verifies its digest and size. A mismatching entry is removed and reported as a miss.
Sourcepub async fn insert(
&self,
checksum: &Checksum,
source: &Path,
size: u64,
) -> Result<PathBuf>
pub async fn insert( &self, checksum: &Checksum, source: &Path, size: u64, ) -> Result<PathBuf>
Inserts a verified file into the cache. If an entry already exists with the expected size it is reused.
Sourcepub async fn materialize(
&self,
cached: &Path,
destination: &Path,
size: u64,
) -> Result<()>
pub async fn materialize( &self, cached: &Path, destination: &Path, size: u64, ) -> Result<()>
Hardlinks or copies a cached file to destination. The caller is
responsible for applying overwrite/rename conflict policy first.
Sourcepub async fn stats(&self) -> Result<CacheStats>
pub async fn stats(&self) -> Result<CacheStats>
Returns aggregate entry and byte counts.
Sourcepub async fn clear(&self) -> Result<u64>
pub async fn clear(&self) -> Result<u64>
Removes all cache entries and temporary files, returning the number of bytes removed.
Sourcepub async fn prune_temp(&self) -> Result<u64>
pub async fn prune_temp(&self) -> Result<u64>
Removes incomplete temporary files, returning the number removed.
Sourcepub async fn prune(
&self,
older_than: Option<Duration>,
max_bytes: Option<u64>,
) -> Result<CachePruneReport>
pub async fn prune( &self, older_than: Option<Duration>, max_bytes: Option<u64>, ) -> Result<CachePruneReport>
Removes entries older than older_than and, when max_bytes is set,
the oldest remaining entries until the cache fits the limit. Passing
both as None only reports current totals.
Sourcepub async fn prune_preview(
&self,
older_than: Option<Duration>,
max_bytes: Option<u64>,
) -> Result<CachePruneReport>
pub async fn prune_preview( &self, older_than: Option<Duration>, max_bytes: Option<u64>, ) -> Result<CachePruneReport>
Reports what ContentCache::prune would remove without deleting
anything.