Cache Module

Caching functionality

get_cache(path=None, ttl_days=None, max_size=None)

Create a persistent cache.

Default caching functionality can be controlled with environment variables:

  • WBDATA_CACHE_PATH: path for the cache (default: system default application cache)
  • WBDATA_CACHE_TTL_DAYS: number of days to cache results (default: 7)
  • WBDATA_CACHE_MAX_SIZE: maximum number of items to cache (default: 100)

The cache returned is a shelved_cache.PersistentCache that wraps a cachetools.TTLCache object with the desired parameters. The cache is cleaned up on load.

Parameters:
  • path (Union[str, Path, None], default: None ) –

    path to the cache. If None, value of WBDATA_CACHE_PATH

  • ttl_days (Union[int, None], default: None ) –

    number of days to cache results. If None, value of WBDATA_CACHE_TTL_DAYS

  • max_size (Union[int, None], default: None ) –

    maximum number of items to cache. If None, value of WBDATA_CACHE_MAX_SIZE.