pub struct ReadOnlyCache { /* private fields */ }Expand description
A ReadOnlyCache wraps an arbitrary number of
crate::plain::Cache and crate::sharded::Cache, and attempts
to satisfy ReadOnlyCache::get and ReadOnlyCache::touch
requests by hitting each constituent cache in order. This
interface hides the difference between plain and sharded cache
directories, and should be the first resort for read-only uses.
The default cache wraps an empty set of constituent caches and performs no consistency check.
ReadOnlyCache objects are stateless and cheap to clone; don’t
put an Arc on them. Avoid creating multiple
ReadOnlyCaches for the same stack of directories: there is no
internal state to maintain, so multiple instances simply waste
memory without any benefit.
Implementations§
Source§impl ReadOnlyCache
impl ReadOnlyCache
Sourcepub fn get<'a>(&self, key: impl Into<Key<'a>>) -> Result<Option<File>>
pub fn get<'a>(&self, key: impl Into<Key<'a>>) -> Result<Option<File>>
Attempts to open a read-only file for key. The
ReadOnlyCache will query each constituent cache in order
of registration, and return a read-only file for the first
hit.
Fails with ErrorKind::InvalidInput if key.name is
invalid (empty, or starts with a dot or a forward or back slash).
Returns None if no file for key can be found in any of
the constituent caches, and bubbles up the first I/O error
encountered, if any.
In the worst case, each call to get attempts to open two
files for each cache directory in the ReadOnlyCache stack.
Sourcepub fn touch<'a>(&self, key: impl Into<Key<'a>>) -> Result<bool>
pub fn touch<'a>(&self, key: impl Into<Key<'a>>) -> Result<bool>
Marks a cache entry for key as accessed (read). The
ReadOnlyCache will touch the same file that would be
returned by get.
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 could be found, and bubbles
up the first I/O error encountered, if any.
In the worst case, each call to touch attempts to update the
access time on two files for each cache directory in the
ReadOnlyCache stack.
Trait Implementations§
Source§impl Clone for ReadOnlyCache
impl Clone for ReadOnlyCache
Source§fn clone(&self) -> ReadOnlyCache
fn clone(&self) -> ReadOnlyCache
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more