Struct sccache::lru_disk_cache::LruDiskCache
source · [−]pub struct LruDiskCache<S: BuildHasher = RandomState> { /* private fields */ }
Expand description
An LRU cache of files on disk.
Implementations
sourceimpl LruDiskCache
impl LruDiskCache
sourcepub fn new<T>(path: T, size: u64) -> Result<Self> where
PathBuf: From<T>,
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.
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
.
Auto Trait Implementations
impl<S> RefUnwindSafe for LruDiskCache<S> where
S: RefUnwindSafe,
impl<S> Send for LruDiskCache<S> where
S: Send,
impl<S> Sync for LruDiskCache<S> where
S: Sync,
impl<S> Unpin for LruDiskCache<S> where
S: Unpin,
impl<S> UnwindSafe for LruDiskCache<S> where
S: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more