pub struct DiskCache { /* private fields */ }Expand description
Disk-based response cache with configurable TTL.
Caches HTTP response text as JSON files keyed by a hash of the request URL, query parameters, and optional POST body. Expired entries are treated as cache misses and silently ignored.
§Atomic writes
Writes use a temporary file + rename pattern to prevent partial reads from concurrent access.
Implementations§
Source§impl DiskCache
impl DiskCache
Sourcepub fn new(cache_dir: PathBuf, ttl: Duration) -> Result<DiskCache, Error>
pub fn new(cache_dir: PathBuf, ttl: Duration) -> Result<DiskCache, Error>
Create a cache storing entries in cache_dir with the given TTL.
Creates the directory (and parents) if it doesn’t exist.
Sourcepub fn default_location(ttl: Duration) -> Result<DiskCache, Error>
pub fn default_location(ttl: Duration) -> Result<DiskCache, Error>
Create a cache in the platform-standard cache directory.
- Linux:
~/.cache/papers/requests - macOS:
~/Library/Caches/papers/requests - Windows:
{FOLDERID_LocalAppData}/papers/requests
Returns Err if no cache directory can be determined or created.
Sourcepub fn get(
&self,
url: &str,
query: &[(&str, String)],
body: Option<&str>,
) -> Option<String>
pub fn get( &self, url: &str, query: &[(&str, String)], body: Option<&str>, ) -> Option<String>
Look up a cached response.
Returns None on cache miss, expired entry, or any I/O / parse error.
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