Skip to main content

ContentCache

Struct ContentCache 

Source
pub struct ContentCache { /* private fields */ }
Expand description

A content-addressed cache rooted at a directory.

Implementations§

Source§

impl ContentCache

Source

pub fn new(root: impl Into<PathBuf>) -> Result<Self>

Creates a cache rooted at root, creating the directory if needed.

Source

pub fn root(&self) -> &Path

Returns the cache root.

Source

pub fn entry_path(&self, checksum: &Checksum) -> Result<PathBuf>

Returns the path an entry with checksum would use.

Source

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.

Source

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.

Source

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.

Source

pub async fn stats(&self) -> Result<CacheStats>

Returns aggregate entry and byte counts.

Source

pub async fn clear(&self) -> Result<u64>

Removes all cache entries and temporary files, returning the number of bytes removed.

Source

pub async fn prune_temp(&self) -> Result<u64>

Removes incomplete temporary files, returning the number removed.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for ContentCache

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ContentCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more