pub struct CacheManager {
pub cache_dir: PathBuf,
pub offline: bool,
/* private fields */
}Expand description
Downloads and caches MTGJSON data files from the CDN.
Checks Meta.json for version changes and re-downloads when stale. Individual files are downloaded lazily on first access.
Fields§
§cache_dir: PathBufDirectory where cached files are stored.
offline: boolIf true, never download from CDN (use cached files only).
Implementations§
Source§impl CacheManager
impl CacheManager
Sourcepub fn new(
cache_dir: Option<PathBuf>,
offline: bool,
timeout: Duration,
on_progress: Option<ProgressCallback>,
) -> Result<Self>
pub fn new( cache_dir: Option<PathBuf>, offline: bool, timeout: Duration, on_progress: Option<ProgressCallback>, ) -> Result<Self>
Create a new cache manager.
If cache_dir is None, uses the platform-appropriate default cache directory.
Creates the cache directory if it does not exist.
Sourcepub fn remote_version(&mut self) -> Result<Option<String>>
pub fn remote_version(&mut self) -> Result<Option<String>>
Fetch the current MTGJSON version from Meta.json on the CDN.
Returns the version string (e.g. "5.2.2+20240101"), or None if
offline or the CDN is unreachable. Caches the result for subsequent calls.
Sourcepub fn is_stale(&mut self) -> Result<bool>
pub fn is_stale(&mut self) -> Result<bool>
Check if local cache is out of date compared to the CDN.
Returns true if there is no local cache or the CDN has a newer version.
Returns false if up to date or if the CDN is unreachable.