imf_reader.cache.http
Shared requests-cache CachedSession for HTTP-layer caching.
All HTTP call sites in imf_reader route through get_session() when caching is enabled, falling back to bare requests when the cache is disabled (so tests that patch requests.get / requests.post directly keep working).
Attributes
Functions
|
|
|
Return the shared CachedSession, rebuilding it if the cache root has changed. |
|
Invalidate the cached session when the cache root changes. |
|
Close the SQLite-backed session before the cache directory is removed. |
Module Contents
- imf_reader.cache.http._session: requests_cache.CachedSession | None = None
- imf_reader.cache.http._session_root: pathlib.Path | None = None
- imf_reader.cache.http._build_session(root: pathlib.Path) requests_cache.CachedSession
- imf_reader.cache.http.get_session() requests_cache.CachedSession
Return the shared CachedSession, rebuilding it if the cache root has changed.
Compares the current resolved root against the one the session was built against. The listener pattern is an optimization; this guard ensures set_cache_dir() takes effect even if the listener registry was cleared (e.g. by a test fixture) between calls.
- imf_reader.cache.http._on_root_change(new_root: pathlib.Path) None
Invalidate the cached session when the cache root changes.
- imf_reader.cache.http._on_http_clear() None
Close the SQLite-backed session before the cache directory is removed.
A scope=’http’ or scope=’all’ clear deletes
<root>/http/from disk; if the open SQLite connection survives, it can keep serving deleted cache rows on Unix or block the directory removal on Windows. Closing the session here forces a fresh connection on the nextget_session()call.