Skip to main content

DiskCache

Struct DiskCache 

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

The local disk tier.

Implementations§

Source§

impl DiskCache

Source

pub fn list(&self) -> Vec<Listed>

Every file under <root>/v2, classified. Files that vanish while listing are skipped.

Source

pub fn usage(&self) -> Usage

Entry files and their total size, without reading them.

Source

pub fn check_file( path: &Path, key: &QueryKey, ) -> Result<(Meta, Vec<u8>), Problem>

Fully checks the entry file at path for key: integrity (header, key, hash) and the shape of the reply for its command.

§Errors

The first problem found.

Source

pub fn summarize(&self) -> Summary

Summarizes the cache: entries and bytes by command, unknown answers and their recorded effort, and files that are not valid entries. Reads every entry; removes nothing.

Source

pub fn verify(&self, remove: bool) -> VerifyReport

Checks every file under <root>/v2. With remove, deletes each bad one. Temporary files younger than STALE_TEMP are skipped.

Source

pub fn gc(&self, max_bytes: u64) -> GcReport

Evicts the least recently used entries until entry files take at most max_bytes, and removes temporary files older than STALE_TEMP. “Used” is the later of a file’s access time (which the daemon refreshes on hits) and its modification time.

Source

pub fn clear(&self) -> Result<Usage>

Removes every entry. The entries directory is first renamed out of the way, so entries disappear at once, then deleted. Returns the number of entries there were.

§Errors

I/O errors renaming or deleting the directory.

Source§

impl DiskCache

Source

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

A cache rooted at root (created on first write).

Source

pub fn root(&self) -> &Path

The cache root.

Source

pub fn entries_dir(&self) -> PathBuf

The directory holding every entry, <root>/v2.

Source

pub fn entry_path(&self, key: &QueryKey) -> PathBuf

The path of key’s entry file.

Source

pub fn get(&self, key: &QueryKey) -> Option<(Meta, Vec<u8>)>

The reply stored for key, if there is a valid entry.

Source

pub fn get_stamped(&self, key: &QueryKey) -> Option<Stored>

The entry stored for key, if valid, with the stamp of the file it was read from. A hit refreshes the file’s access time (at most once per TOUCH_INTERVAL). An invalid entry file is removed.

Source

pub fn stamp_for_hit(&self, key: &QueryKey) -> Option<FileStamp>

The stamp of key’s entry file as it is now, if it is a file. The caller is about to serve this entry from memory, so the access time is refreshed if it is older than TOUCH_INTERVAL, for gc.

Source

pub fn contains(&self, key: &QueryKey) -> bool

Whether an entry file exists for key (valid or not).

Source

pub fn put( &self, key: &QueryKey, reply: &[u8], command: &str, solver: &str, provenance: &str, effort: Option<&Effort>, ) -> Result<()>

Stores reply for key. Existing entries are left alone: content addressing means they hold the same answer.

§Errors

I/O errors creating or writing the entry.

Source

pub fn put_stamped( &self, key: &QueryKey, reply: &[u8], command: &str, solver: &str, provenance: &str, effort: Option<&Effort>, ) -> Result<PutOutcome>

DiskCache::put, reporting whether the entry was written and, if so, the stamp of the file now at the entry’s path.

§Errors

I/O errors creating or writing the entry.

Source

pub fn put_scoped( &self, key: &QueryKey, reply: &[u8], command: &str, context: &StoreContext<'_>, effort: Option<&Effort>, ) -> Result<PutOutcome>

Stores an entry with explicit provenance and verification namespace.

§Errors

I/O errors creating or writing the entry.

Trait Implementations§

Source§

impl Clone for DiskCache

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 DiskCache

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, 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.