pub struct DiskCache<C, S: BuildHasher + Clone = DefaultHashBuilder>{ /* private fields */ }Expand description
An basic disk cache of files on disk.
Implementations§
Source§impl<C> DiskCache<C, DefaultHashBuilder>
impl<C> DiskCache<C, DefaultHashBuilder>
Sourcepub fn new<T>(path: T, size: u64) -> Result<Self>
pub fn new<T>(path: T, size: u64) -> Result<Self>
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>
impl<C, S> DiskCache<C, S>
Sourcepub fn new_with_hasher<T>(path: T, size: u64, hash_builder: S) -> Result<Self>
pub fn new_with_hasher<T>(path: T, size: u64, hash_builder: S) -> Result<Self>
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.
pub fn is_empty(&self) -> bool
Sourcepub fn can_store(&self, size: u64) -> bool
pub fn can_store(&self, size: u64) -> bool
Returns true if the disk cache can store a file of size bytes.
Sourcepub fn insert_with<K: AsRef<OsStr>, F: FnOnce(File) -> Result<()>>(
&mut self,
key: K,
with: F,
) -> Result<()>
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.
Sourcepub fn insert_bytes<K: AsRef<OsStr>>(
&mut self,
key: K,
bytes: &[u8],
) -> Result<()>
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.
Sourcepub fn insert_file<K: AsRef<OsStr>, P: AsRef<OsStr>>(
&mut self,
key: K,
path: P,
) -> Result<()>
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.
Sourcepub fn contains_key<K: AsRef<OsStr>>(&self, key: K) -> bool
pub fn contains_key<K: AsRef<OsStr>>(&self, key: K) -> bool
Return true if a file with path key is in the cache.
Sourcepub fn get_file<K: AsRef<OsStr>>(&mut self, key: K) -> Result<File>
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.