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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Cache
impl RefUnwindSafe for Cache
impl Send for Cache
impl Sync for Cache
impl Unpin for Cache
impl UnwindSafe for Cache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more