pub struct UrlCache {
pub base_directory: PathBuf,
pub files: LazyLock<Mutex<HashMap<String, PathBufRef>>>,
pub directories: LazyLock<Mutex<HashMap<String, PathBufRef>>>,
}Expand description
Cache for a UrlContext.
Fields§
§base_directory: PathBufBase directory.
files: LazyLock<Mutex<HashMap<String, PathBufRef>>>Files owned by this cache.
directories: LazyLock<Mutex<HashMap<String, PathBufRef>>>Directories owned by this cache.
Implementations§
Source§impl UrlCache
impl UrlCache
Sourcepub async fn file_from_async(
&self,
url: &UrlRef,
prefix: &str,
) -> Result<(PathBufRef, bool), UrlError>
Available on crate feature async only.
pub async fn file_from_async( &self, url: &UrlRef, prefix: &str, ) -> Result<(PathBufRef, bool), UrlError>
async only.Get a cache file from a URL.
If it already exists returns the path and true. Otherwise copies the URL to a generated path and returns it and false.
Source§impl UrlCache
impl UrlCache
Sourcepub fn default_base_directory() -> PathBuf
pub fn default_base_directory() -> PathBuf
Default base directory.
Sourcepub fn reset(&self) -> Result<(), UrlError>
pub fn reset(&self) -> Result<(), UrlError>
Resets the cache, deleting all owned files and directories.
Sourcepub fn file(
&self,
key: &str,
prefix: &str,
) -> Result<(PathBufRef, bool), UrlError>
pub fn file( &self, key: &str, prefix: &str, ) -> Result<(PathBufRef, bool), UrlError>
Get a cache file.
If it already exists returns the path and true. Otherwise generates a path and returns it and false.
Sourcepub fn directory(
&self,
key: &str,
prefix: &str,
) -> Result<(PathBufRef, bool), UrlError>
pub fn directory( &self, key: &str, prefix: &str, ) -> Result<(PathBufRef, bool), UrlError>
Get a cache directory.
If it already exists returns the path and true. Otherwise creates it (create_dir_all) in a generated path and returns it and false.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for UrlCache
impl RefUnwindSafe for UrlCache
impl Send for UrlCache
impl Sync for UrlCache
impl Unpin for UrlCache
impl UnwindSafe for UrlCache
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
Mutably borrows from an owned value. Read more