slickbet.cache¶

File-based cache for Livescore API responses.

Enables fast backtesting and hyperparameter optimization by storing API responses locally and reusing them instead of hitting the API.

Examples

>>> # First run: fetch and cache (e.g. 12 weeks backtest)
>>> client = LivescoreClient(cache_dir="data/api_cache")
>>> # ... run backtest ...
>>> # Later runs: use cache only (no API calls)
>>> client = LivescoreClient(cache_dir="data/api_cache", cache_only=True)

Classes¶

ApiCache

File-based cache for API response bodies (JSON).

Functions¶

cache_key(→ str)

Produce a short, filesystem-safe cache key from endpoint and params.

Module Contents¶

class slickbet.cache.ApiCache(cache_dir: str | pathlib.Path)[source]¶

File-based cache for API response bodies (JSON).

Each request is stored as a single JSON file keyed by endpoint + params.

clear() None[source]¶

Remove all cached files in the cache directory.

Returns:

None

get(endpoint: str, params: dict[str, Any] | None) dict | None[source]¶

Load cached response if present.

Parameters:
  • endpoint (str) – API endpoint path.

  • params (dict or None) – Request query parameters.

Returns:

dict or None – Cached JSON body or None if miss.

root¶
set(endpoint: str, params: dict[str, Any] | None, data: dict) None[source]¶

Store response in cache.

Parameters:
  • endpoint (str) – API endpoint path.

  • params (dict or None) – Request query parameters.

  • data (dict) – JSON response body to store.

slickbet.cache.cache_key(endpoint: str, params: dict[str, Any] | None) str[source]¶

Produce a short, filesystem-safe cache key from endpoint and params.

Parameters:
  • endpoint (str) – API endpoint path.

  • params (dict or None) – Request query parameters.

Returns:

str – 32-character hex digest.