pub struct Cache { /* private fields */ }Expand description
A directory of cached responses, keyed by URL.
Each URL is stored as <key>.bin (the bytes) and <key>.json (a CacheEntry without the
bytes), where <key> is the 64-bit FNV-1a hash of the URL in hex. The metadata records the URL
itself, so two URLs whose hashes collide read as a miss rather than as each other’s data. Each
file is written whole to a temporary name and renamed, the metadata last. Nothing locks the
cache: two writers of one URL may leave one’s body beside the other’s fetch time.
Implementations§
Source§impl Cache
impl Cache
Sourcepub fn platform_dir() -> Option<PathBuf>
pub fn platform_dir() -> Option<PathBuf>
The standard place for hpr’s cache on this platform, or None if the environment names no
home folder.
HPR_CACHE_DIR, when set and not empty, wins on every platform; it is used as given, so a
relative path is taken from the current directory. Otherwise:
| platform | folder |
|---|---|
| macOS | $HOME/Library/Caches/hpr-sim |
| Windows | %LOCALAPPDATA%\hpr-sim\cache |
| Linux and other Unix | $XDG_CACHE_HOME/hpr-sim, or $HOME/.cache/hpr-sim |
XDG_CACHE_HOME counts only when it is an absolute path, as the XDG Base Directory
Specification says. The folder is not created until the first write.
Sourcepub fn get(&self, url: &str) -> Result<Option<CacheEntry>, NetError>
pub fn get(&self, url: &str) -> Result<Option<CacheEntry>, NetError>
The cached entry for url, or None if there is none.
§Errors
NetError::Cache if a file exists but cannot be read; NetError::CorruptEntry if the
metadata does not parse.