Struct kismet_cache::sharded::Cache

source ·
pub struct Cache { /* private fields */ }
Expand description

A sharded cache is a hash-sharded directory of cache subdirectories. Each subdirectory is managed as an independent second chance cache directory.

Implementations§

source§

impl Cache

source

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

Returns a new cache for approximately total_capacity files, stores in num_shards subdirectories of base_dir.

source

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

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

Implicitly “touches” the cached file if it exists.

source

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

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

When this temporary file will be published at a known Key, populate key for improved behaviour.

source

pub fn set(&self, key: Key<'_>, value: &Path) -> Result<()>

Inserts or overwrites the file at value as key in the sharded cache directory. There may be two entries for the same key with concurrent set or put calls. Fails with ErrorKind::InvalidInput if key.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, key: Key<'_>, value: &Path) -> Result<()>

Inserts the file at value as key in the cache directory if there is no such cached entry already, or touches the cached file if it already exists. There may be two entries for the same key with concurrent set or put calls. Fails with ErrorKind::InvalidInput if key.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, key: Key<'_>) -> Result<bool>

Marks the cached file key as newly used, if it exists. 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 exists in the cache.

Trait Implementations§

source§

impl Clone for Cache

source§

fn clone(&self) -> Cache

Returns a copy 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 Cache

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V