Cache¶
cxg.cache
¶
CacheState
dataclass
¶
Snapshot of a cache file's current state.
Source code in src/cxg/cache.py
get_cache_dir()
¶
Return the cache directory path, respecting CXG_CACHE_DIR, then config.
Source code in src/cxg/cache.py
get_cache_ttl()
¶
Return the cache TTL in seconds, respecting CXG_CACHE_TTL, then config.
Source code in src/cxg/cache.py
datasets_cache_path()
¶
collections_cache_path()
¶
load_json(path)
¶
Load and parse a JSON file, returning None on failure.
Source code in src/cxg/cache.py
load_datasets_cache()
¶
load_collections_cache()
¶
write_json_atomic(path, payload)
¶
Atomically write a JSON payload using a temp file and rename.
Source code in src/cxg/cache.py
write_datasets_cache(datasets, response_bytes)
¶
Sort, index, and write datasets to the cache file.
Source code in src/cxg/cache.py
write_collections_cache(collections, response_bytes)
¶
Sort, index, and write collections to the cache file.
Source code in src/cxg/cache.py
clear_cache()
¶
Delete all cache files and return a list of removed paths.
Source code in src/cxg/cache.py
is_expired(fetched_at, ttl=None)
¶
Check if a cache timestamp has expired.
A TTL of 0 or a missing timestamp is always considered expired.
Source code in src/cxg/cache.py
current_fetched_at(path)
¶
Read just the fetched_at timestamp from a cache file without loading all data.