imf_reader.cache
Public API for the imf_reader cache subpackage.
Provides a unified interface for cache management across all imf_reader sub-modules (WEO, SDR).
Usage:
import imf_reader.cache as cache
cache.clear_cache() # clear everything
cache.clear_cache(scope="weo") # clear only WEO sublayers
cache.set_cache_dir("/tmp/my_cache")
cache.reset_cache_dir()
print(cache.get_cache_dir())
cache.disable_cache()
cache.enable_cache()
Submodules
Attributes
Exceptions
Raised when a cached or freshly-downloaded bulk payload (e.g., the WEO SDMX zip) fails |
Functions
|
Return the WEO bulk-download (SDMX zip) sublayer directory. |
|
Return the parsed-DataFrame sublayer directory. |
|
Return the HTTP-layer (requests-cache) sublayer directory. |
|
Clear any programmatic override, restoring env-var or platformdirs default. |
|
Override the cache root for this process. |
|
Clear cached data for the named scope. |
|
Re-enable caching after a previous disable_cache() call. |
|
Disable caching for this process. |
Package Contents
- exception imf_reader.cache.BulkPayloadCorruptError
Bases:
ExceptionRaised when a cached or freshly-downloaded bulk payload (e.g., the WEO SDMX zip) fails integrity validation. The corrupt cache entry is removed before this is raised, so the next call re-downloads cleanly.
- imf_reader.cache.get_bulk_cache_dir() pathlib.Path
Return the WEO bulk-download (SDMX zip) sublayer directory.
- imf_reader.cache.get_dataframe_cache_dir() pathlib.Path
Return the parsed-DataFrame sublayer directory.
Note: imf_reader writes parsed DataFrames into per-domain sublayers (
sdr,weo_api,weo_sdmx_parsed). This helper returns the SDR sublayer for parity withoda_reader._cache.config; useget_active_root() / "<sublayer>"for the WEO variants.
- imf_reader.cache.get_http_cache_path() pathlib.Path
Return the HTTP-layer (requests-cache) sublayer directory.
- imf_reader.cache.reset_cache_dir() None
Clear any programmatic override, restoring env-var or platformdirs default.
Triggers all registered listeners with the restored root.
- imf_reader.cache.set_cache_dir(path: str | pathlib.Path) None
Override the cache root for this process.
Triggers all registered listeners with the new root. No I/O at the old path. Overrides any IMF_READER_CACHE_DIR env-var setting until reset_cache_dir() runs.
- Parameters:
path – New cache root base (version segment is appended automatically).
- imf_reader.cache.get_cache_dir
- imf_reader.cache.clear_cache(scope: Literal['all', 'weo', 'sdr', 'http'] = 'all') None
Clear cached data for the named scope.
- Parameters:
scope –
Which sublayers to remove.
"all"(default) — remove every immediate subdir of the cache root. Uses a filesystem walk so future sublayers are automatically included (avoids the F1 failure mode of silently leaking newly-added sublayers)."weo"— removeweo_sdmx,weo_sdmx_parsed, andweo_api."sdr"— remove thesdrsublayer."http"— remove thehttpsublayer.
- imf_reader.cache.enable_cache() None
Re-enable caching after a previous disable_cache() call.
Has no effect if caching is already enabled.
- imf_reader.cache.disable_cache() None
Disable caching for this process.
All decorated functions bypass both the read and write cache paths and call through to the underlying function directly. Has no effect on already-cached data on disk.