[−][src]Struct lru_disk_cache::LruDiskCache
An LRU cache of files on disk.
Methods
impl LruDiskCache
[src]
pub fn new<T>(path: T, size: u64) -> Result<Self> where
PathBuf: From<T>,
[src]
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.
pub fn size(&self) -> u64
[src]
Return the current size of all the files in the cache.
pub fn capacity(&self) -> u64
[src]
Return the maximum size of the cache.
pub fn path(&self) -> &Path
[src]
Return the path in which the cache is stored.
pub fn can_store(&self, size: u64) -> bool
[src]
Returns true
if the disk cache can store a file of size
bytes.
pub fn insert_with<K: AsRef<OsStr>, F: FnOnce(File) -> Result<()>>(
&mut self,
key: K,
with: F
) -> Result<()>
[src]
&mut self,
key: K,
with: F
) -> Result<()>
Add a file by calling with
with the open File
corresponding to the cache at path key
.
pub fn insert_bytes<K: AsRef<OsStr>>(
&mut self,
key: K,
bytes: &[u8]
) -> Result<()>
[src]
&mut self,
key: K,
bytes: &[u8]
) -> Result<()>
Add a file with bytes
as its contents to the cache at path key
.
pub fn insert_file<K: AsRef<OsStr>, P: AsRef<OsStr>>(
&mut self,
key: K,
path: P
) -> Result<()>
[src]
&mut self,
key: K,
path: P
) -> Result<()>
Add an existing file at path
to the cache at path key
.
pub fn contains_key<K: AsRef<OsStr>>(&self, key: K) -> bool
[src]
Return true
if a file with path key
is in the cache.
pub fn get_file<K: AsRef<OsStr>>(&mut self, key: K) -> Result<File>
[src]
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
.
pub fn get<K: AsRef<OsStr>>(&mut self, key: K) -> Result<Box<dyn ReadSeek>>
[src]
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.
Auto Trait Implementations
impl<S> Sync for LruDiskCache<S> where
S: Sync,
S: Sync,
impl<S> Send for LruDiskCache<S> where
S: Send,
S: Send,
impl<S> Unpin for LruDiskCache<S> where
S: Unpin,
S: Unpin,
impl<S> RefUnwindSafe for LruDiskCache<S> where
S: RefUnwindSafe,
S: RefUnwindSafe,
impl<S> UnwindSafe for LruDiskCache<S> where
S: UnwindSafe,
S: UnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,