Struct Cache

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

A “plain” cache is a single directory of files. Given a capacity of k files, we will trigger a second chance maintance roughly every k / 3 (k / 6 in the long run, given the way PeriodicTrigger is implemented) insertions.

Implementations§

Source§

impl Cache

Source

pub fn new(base_dir: PathBuf, capacity: usize) -> Cache

Returns a new cache for approximately capacity files in base_dir.

Source

pub fn get(&self, name: &str) -> Result<Option<File>>

Returns a read-only file for name in the cache directory if it exists, or None if there is no such file. Fails with ErrorKind::InvalidInput if name is invalid (empty, or starts with a dot or a forward or back slash).

Implicitly “touches” the cached file name if it exists.

Source

pub fn temp_dir(&self) -> Result<Cow<'_, Path>>

Returns a temporary directory suitable for temporary files that will be published to the cache directory.

Source

pub fn set(&self, name: &str, value: &Path) -> Result<()>

Inserts or overwrites the file at value as name in the cache directory. Fails with ErrorKind::InvalidInput if name is invalid (empty, or starts with a dot or a forward or back slash).

Always consumes the file at value on success; may consume it on error.

Source

pub fn put(&self, name: &str, value: &Path) -> Result<()>

Inserts the file at value as name in the cache directory if there is no such cached entry already, or touches the cached file if it already exists. Fails with ErrorKind::InvalidInput if name is invalid (empty, or starts with a dot or a forward or back slash).

Always consumes the file at value on success; may consume it on error.

Source

pub fn touch(&self, name: &str) -> Result<bool>

Marks the cached file name as newly used, if it exists. Fails with ErrorKind::InvalidInput if name is invalid (empty, or starts with a dot or a forward or back slash).

Returns whether name exists.

Trait Implementations§

Source§

impl Clone for Cache

Source§

fn clone(&self) -> Cache

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Cache

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Cache

§

impl RefUnwindSafe for Cache

§

impl Send for Cache

§

impl Sync for Cache

§

impl Unpin for Cache

§

impl UnwindSafe for Cache

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V