api_24sea.cache#

Optional, bounded local storage for successful data-query responses.

Classes#

QueryCache

Cache query responses on disk without storing credentials or pickles.

Functions#

query_cache_key(→ str)

Hash the query, endpoint, headers, and credential scope into a key.

resolve_query_cache(→ Optional[QueryCache])

Resolve the opt-in shorthand without creating directories eagerly.

Module Contents#

class QueryCache(directory: str | pathlib.Path | None = None, ttl: float = 86400, max_bytes: int = 1024**3)#

Cache query responses on disk without storing credentials or pickles.

Parameters#

directorystr or pathlib.Path, optional

Dedicated cache directory. Defaults to the user’s XDG cache directory.

ttlfloat, default 86400

Maximum age of a cached response, in seconds.

max_bytesint, default 1073741824

Maximum total size of cache entries. Oldest entries are evicted first.

Notes#

Cached values are snapshots. Use force_cache_miss=True to refresh both local and server caches after underlying data or permissions change.

get(key: str, url: str, method: str) → httpx.Response | None#

Read an intact, unexpired response, or return a cache miss.

put(key: str, response: httpx.Response) → None#

Atomically store a successfully decoded response and enforce size.

prune() → None#

Remove expired entries and then the oldest entries over the limit.

clear() → None#

Remove this cache’s query entries while preserving unrelated files.

query_cache_key(url: str, method: str, params: Dict, headers: Dict[str, str] | None, auth: httpx.BasicAuth | None) → str#

Hash the query, endpoint, headers, and credential scope into a key.

No credentials, query parameters, or request headers are persisted in the filename or cache metadata. Refresh flags do not change result identity.

resolve_query_cache(cache: bool | QueryCache) → QueryCache | None#

Resolve the opt-in shorthand without creating directories eagerly.