DiskCache

Struct DiskCache 

Source
pub struct DiskCache<C, S: BuildHasher + Clone = DefaultHashBuilder>
where C: Cache<OsString, u64, S, FileSize>,
{ /* private fields */ }
Expand description

An basic disk cache of files on disk.

Implementations§

Source§

impl<C> DiskCache<C, DefaultHashBuilder>

Source

pub fn new<T>(path: T, size: u64) -> Result<Self>
where PathBuf: From<T>,

Create an LruDiskCache that stores files in path, limited to size bytes.

Existing files in path will be stored with their last-modified time from the filesystem used as the order for the recency of their use. Any files that are individually larger than size bytes will be removed.

The cache is not observant of changes to files under path from external sources, it expects to have sole maintence of the contents.

Source§

impl<C, S> DiskCache<C, S>
where C: Cache<OsString, u64, S, FileSize>, S: BuildHasher + Clone,

Source

pub fn new_with_hasher<T>(path: T, size: u64, hash_builder: S) -> Result<Self>
where PathBuf: From<T>,

Create an LruDiskCache that stores files in path, limited to size bytes.

Existing files in path will be stored with their last-modified time from the filesystem used as the order for the recency of their use. Any files that are individually larger than size bytes will be removed.

The cache is not observant of changes to files under path from external sources, it expects to have sole maintence of the contents.

Source

pub fn size(&self) -> u64

Return the current size of all the files in the cache.

Source

pub fn len(&self) -> usize

Return the count of entries in the cache.

Source

pub fn is_empty(&self) -> bool

Source

pub fn capacity(&self) -> u64

Return the maximum size of the cache.

Source

pub fn path(&self) -> &Path

Return the path in which the cache is stored.

Source

pub fn can_store(&self, size: u64) -> bool

Returns true if the disk cache can store a file of size bytes.

Source

pub fn insert_with<K: AsRef<OsStr>, F: FnOnce(File) -> Result<()>>( &mut self, key: K, with: F, ) -> Result<()>

Add a file by calling with with the open File corresponding to the cache at path key.

Source

pub fn insert_bytes<K: AsRef<OsStr>>( &mut self, key: K, bytes: &[u8], ) -> Result<()>

Add a file with bytes as its contents to the cache at path key.

Source

pub fn insert_file<K: AsRef<OsStr>, P: AsRef<OsStr>>( &mut self, key: K, path: P, ) -> Result<()>

Add an existing file at path to the cache at path key.

Source

pub fn contains_key<K: AsRef<OsStr>>(&self, key: K) -> bool

Return true if a file with path key is in the cache.

Source

pub fn get_file<K: AsRef<OsStr>>(&mut self, key: K) -> Result<File>

Get an opened File for key, if one exists and can be opened. Updates the LRU state of the file if present. Avoid using this method if at all possible, prefer .get.

Source

pub fn get<K: AsRef<OsStr>>(&mut self, key: K) -> Result<Box<dyn ReadSeek>>

Get an opened readable and seekable handle to the file at key, if one exists and can be opened. Updates the LRU state of the file if present.

Source

pub fn remove<K: AsRef<OsStr>>(&mut self, key: K) -> Result<()>

Remove the given key from the cache.

Auto Trait Implementations§

§

impl<C, S> Freeze for DiskCache<C, S>
where S: Freeze, C: Freeze,

§

impl<C, S> RefUnwindSafe for DiskCache<C, S>

§

impl<C, S> Send for DiskCache<C, S>
where S: Send, C: Send,

§

impl<C, S> Sync for DiskCache<C, S>
where S: Sync, C: Sync,

§

impl<C, S> Unpin for DiskCache<C, S>
where S: Unpin, C: Unpin,

§

impl<C, S> UnwindSafe for DiskCache<C, S>
where S: UnwindSafe, C: UnwindSafe,

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