pub struct Cache { /* private fields */ }Expand description
Owns data about cached sources and is responsible for its persistence.
Implementations§
Source§impl Cache
impl Cache
Sourcepub fn read<P>(cache_dir: P) -> Result<Self, Error>
pub fn read<P>(cache_dir: P) -> Result<Self, Error>
Read the cache in the given directory.
Error if the directory or cache file do not exist, of if a deserialisation error occurs when reading the cache file
Sourcepub fn new<P>(cache_dir: P) -> Result<Self, Error>
pub fn new<P>(cache_dir: P) -> Result<Self, Error>
Create a new cache in the given directory.
Error if the directory doesn’t exist, or if there is already a cache file in this directory.
Sourcepub fn load_or_create<P>(cache_dir: P) -> Result<Self, Error>
pub fn load_or_create<P>(cache_dir: P) -> Result<Self, Error>
Loads the cache from a JSON file in the given directory, creating a new cache if the file
does not exist. Requires that cache_dir exists. Note that this function doesn’t
actually create the cache file - this happens when the cache is saved.
Returns an error if cache_dir doesn’t exist, or if a deserialisation error occurs when
reading the cache file.
Sourcepub fn save(&self) -> Result<(), Error>
pub fn save(&self) -> Result<(), Error>
Saves the cache in the directory where it was created.
Returns an error if a serialisation or I/O error occurs.
Sourcepub fn cache_file(&self) -> &Path
pub fn cache_file(&self) -> &Path
Get the cache file path.
Sourcepub fn cached_path(&self, source: &Source) -> CacheDir
pub fn cached_path(&self, source: &Source) -> CacheDir
Calculate the absolute path where a fetched source would be stored within the cache
Sourcepub fn items(&self) -> &CacheItems
pub fn items(&self) -> &CacheItems
Get a reference to the cache items.
Sourcepub fn items_mut(&mut self) -> &mut CacheItems
pub fn items_mut(&mut self) -> &mut CacheItems
Get a mutable reference to the cache items.
Sourcepub fn cache_file_exists<P>(cache_dir: P) -> bool
pub fn cache_file_exists<P>(cache_dir: P) -> bool
Check whether the cache file exists in the given directory.