pub struct Cache { /* private fields */ }Expand description
A sharded cache is a hash-sharded directory of cache subdirectories. Each subdirectory is managed as an independent second chance cache directory.
Implementations§
Source§impl Cache
impl Cache
Sourcepub fn new(base_dir: PathBuf, num_shards: usize, total_capacity: usize) -> Cache
pub fn new(base_dir: PathBuf, num_shards: usize, total_capacity: usize) -> Cache
Returns a new cache for approximately total_capacity files,
stores in num_shards subdirectories of base_dir.
Sourcepub fn get(&self, key: Key<'_>) -> Result<Option<File>>
pub fn get(&self, key: Key<'_>) -> Result<Option<File>>
Returns a read-only file for key in the shard cache
directory if it exists, or None if there is no such file.
Fails with ErrorKind::InvalidInput if key.name is invalid
(empty, or starts with a dot or a forward or back slash).
Implicitly “touches” the cached file if it exists.
Sourcepub fn temp_dir(&self, key: Option<Key<'_>>) -> Result<Cow<'_, Path>>
pub fn temp_dir(&self, key: Option<Key<'_>>) -> Result<Cow<'_, Path>>
Returns a temporary directory suitable for temporary files that will be published to the shard cache directory.
When this temporary file will be published at a known Key,
populate key for improved behaviour.
Sourcepub fn set(&self, key: Key<'_>, value: &Path) -> Result<()>
pub fn set(&self, key: Key<'_>, value: &Path) -> Result<()>
Inserts or overwrites the file at value as key in the
sharded cache directory. There may be two entries for the
same key with concurrent set or put calls. Fails with
ErrorKind::InvalidInput if key.name is invalid (empty, or
starts with a dot or a forward or back slash).
Always consumes the file at value on success; may consume it
on error.
Sourcepub fn put(&self, key: Key<'_>, value: &Path) -> Result<()>
pub fn put(&self, key: Key<'_>, value: &Path) -> Result<()>
Inserts the file at value as key in the cache directory if
there is no such cached entry already, or touches the cached
file if it already exists. There may be two entries for the
same key with concurrent set or put calls. Fails with
ErrorKind::InvalidInput if key.name is invalid (empty, or
starts with a dot or a forward or back slash).
Always consumes the file at value on success; may consume it
on error.