pub struct Cache { /* private fields */ }Expand description
In-memory cache backed by a JSON file.
Implementations§
Source§impl Cache
impl Cache
Sourcepub fn load(path: PathBuf, ttl: Duration) -> Self
pub fn load(path: PathBuf, ttl: Duration) -> Self
Load a cache from path, dropping entries older than ttl.
Infallible: a missing, unreadable, or corrupt file yields an empty cache (a warning is logged). The cache should never be the reason a scan fails.
Sourcepub fn get(&self, site: &Site, username: &Username) -> Option<CheckOutcome>
pub fn get(&self, site: &Site, username: &Username) -> Option<CheckOutcome>
Look up a cached outcome for site + username.
Returns None on a miss, a TTL expiry, or a site-signature mismatch
(the site definition changed since the entry was stored).
Sourcepub fn put(&mut self, site: &Site, username: &Username, outcome: CheckOutcome)
pub fn put(&mut self, site: &Site, username: &Username, outcome: CheckOutcome)
Store an outcome. Uncertain outcomes are ignored (not cached).
Sourcepub fn save(&self) -> Result<()>
pub fn save(&self) -> Result<()>
Persist the cache to disk if anything changed since load. Writes atomically (temp file + rename) and creates parent directories.
Sourcepub fn clear(path: &Path) -> Result<()>
pub fn clear(path: &Path) -> Result<()>
Delete the cache file at path. A missing file is not an error.
Sourcepub fn default_path() -> PathBuf
pub fn default_path() -> PathBuf
Default cache file location: $XDG_CACHE_HOME/adler/cache.json,
falling back to $HOME/.cache/adler/cache.json, then a relative
path if neither env var is set.