pub struct DiskCache { /* private fields */ }Expand description
Disk cache rooted at an XDG (or override) directory.
Implementations§
Source§impl DiskCache
impl DiskCache
Sourcepub fn new(root: PathBuf, ttl: Duration, max_bytes: u64) -> Self
pub fn new(root: PathBuf, ttl: Duration, max_bytes: u64) -> Self
Create a cache at root with the given TTL and byte budget.
Sourcepub fn get(&self, url: &Url, accept: &str) -> Option<HttpResponse>
pub fn get(&self, url: &Url, accept: &str) -> Option<HttpResponse>
Look up a successful GET response. Returns None on miss, expire, or corrupt entry.
Sourcepub fn put(&self, url: &Url, accept: &str, resp: &HttpResponse) -> AppResult<()>
pub fn put(&self, url: &Url, accept: &str, resp: &HttpResponse) -> AppResult<()>
Persist a successful response. Best-effort; failures are non-fatal at call sites.
§Errors
Returns ErrorKind::Internal on filesystem create/write/rename failures or
when cache metadata cannot be serialized.
Sourcepub fn clear(&self) -> AppResult<CacheClearResult>
pub fn clear(&self) -> AppResult<CacheClearResult>
Remove every entry under http/v1 (temps included).
§Errors
Returns ErrorKind::Internal when the cache directory cannot be read.
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Inventory of on-disk entries and budget.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DiskCache
impl RefUnwindSafe for DiskCache
impl Send for DiskCache
impl Sync for DiskCache
impl Unpin for DiskCache
impl UnsafeUnpin for DiskCache
impl UnwindSafe for DiskCache
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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