imf_reader.cache.http ===================== .. py:module:: imf_reader.cache.http .. autoapi-nested-parse:: 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 ---------- .. autoapisummary:: imf_reader.cache.http._session imf_reader.cache.http._session_root Functions --------- .. autoapisummary:: imf_reader.cache.http._build_session imf_reader.cache.http.get_session imf_reader.cache.http._on_root_change imf_reader.cache.http._on_http_clear Module Contents --------------- .. py:data:: _session :type: requests_cache.CachedSession | None :value: None .. py:data:: _session_root :type: pathlib.Path | None :value: None .. py:function:: _build_session(root: pathlib.Path) -> requests_cache.CachedSession .. py:function:: 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. .. py:function:: _on_root_change(new_root: pathlib.Path) -> None Invalidate the cached session when the cache root changes. .. py:function:: _on_http_clear() -> None Close the SQLite-backed session before the cache directory is removed. A scope='http' or scope='all' clear deletes ``/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 next ``get_session()`` call.