ReadOnlyCache

Struct ReadOnlyCache 

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

A ReadOnlyCache wraps an arbitrary number of crate::plain::Cache and crate::sharded::Cache, and attempts to satisfy ReadOnlyCache::get and ReadOnlyCache::touch requests by hitting each constituent cache in order. This interface hides the difference between plain and sharded cache directories, and should be the first resort for read-only uses.

The default cache wraps an empty set of constituent caches and performs no consistency check.

ReadOnlyCache objects are stateless and cheap to clone; don’t put an Arc on them. Avoid creating multiple ReadOnlyCaches for the same stack of directories: there is no internal state to maintain, so multiple instances simply waste memory without any benefit.

Implementations§

Source§

impl ReadOnlyCache

Source

pub fn get<'a>(&self, key: impl Into<Key<'a>>) -> Result<Option<File>>

Attempts to open a read-only file for key. The ReadOnlyCache will query each constituent cache in order of registration, and return a read-only file for the first hit.

Fails with ErrorKind::InvalidInput if key.name is invalid (empty, or starts with a dot or a forward or back slash).

Returns None if no file for key can be found in any of the constituent caches, and bubbles up the first I/O error encountered, if any.

In the worst case, each call to get attempts to open two files for each cache directory in the ReadOnlyCache stack.

Source

pub fn touch<'a>(&self, key: impl Into<Key<'a>>) -> Result<bool>

Marks a cache entry for key as accessed (read). The ReadOnlyCache will touch the same file that would be returned by get.

Fails with ErrorKind::InvalidInput if key.name is invalid (empty, or starts with a dot or a forward or back slash).

Returns whether a file for key could be found, and bubbles up the first I/O error encountered, if any.

In the worst case, each call to touch attempts to update the access time on two files for each cache directory in the ReadOnlyCache stack.

Trait Implementations§

Source§

impl Clone for ReadOnlyCache

Source§

fn clone(&self) -> ReadOnlyCache

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ReadOnlyCache

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ReadOnlyCache

Source§

fn default() -> ReadOnlyCache

Returns the “default value” for a type. 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> 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