pub struct Cache { /* private fields */ }Expand description
A “plain” cache is a single directory of files. Given a capacity
of k files, we will trigger a second chance maintance roughly
every k / 3 (k / 6 in the long run, given the way
PeriodicTrigger is implemented) insertions.
Implementations§
Source§impl Cache
impl Cache
Sourcepub fn new(base_dir: PathBuf, capacity: usize) -> Cache
pub fn new(base_dir: PathBuf, capacity: usize) -> Cache
Returns a new cache for approximately capacity files in
base_dir.
Sourcepub fn get(&self, name: &str) -> Result<Option<File>>
pub fn get(&self, name: &str) -> Result<Option<File>>
Returns a read-only file for name in the cache directory if
it exists, or None if there is no such file. Fails with
ErrorKind::InvalidInput if name is invalid (empty, or
starts with a dot or a forward or back slash).
Implicitly “touches” the cached file name if it exists.
Sourcepub fn temp_dir(&self) -> Result<Cow<'_, Path>>
pub fn temp_dir(&self) -> Result<Cow<'_, Path>>
Returns a temporary directory suitable for temporary files that will be published to the cache directory.
Sourcepub fn set(&self, name: &str, value: &Path) -> Result<()>
pub fn set(&self, name: &str, value: &Path) -> Result<()>
Inserts or overwrites the file at value as name in the
cache directory. Fails with ErrorKind::InvalidInput if
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, name: &str, value: &Path) -> Result<()>
pub fn put(&self, name: &str, value: &Path) -> Result<()>
Inserts the file at value as name in the cache directory
if there is no such cached entry already, or touches the
cached file if it already exists. Fails with
ErrorKind::InvalidInput if 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.