FileCache
- class UnleashClient.cache.FileCache(name: str, directory: str | None = None, request_timeout: int = 30)
The default cache for UnleashClient. Uses fcache behind the scenes.
You can boostrap the FileCache with initial configuration to improve resiliency on startup. To do so:
Create a new FileCache instance.
Bootstrap the FileCache.
Pass your FileCache instance to UnleashClient at initialization along with boostrap=true.
You can bootstrap from a dictionary, a json file, or from a URL. In all cases, configuration should match the Unleash /api/client/features endpoint.
Example:
from pathlib import Path from UnleashClient.cache import FileCache from UnleashClient import UnleashClient my_cache = FileCache("HAMSTER_API") my_cache.bootstrap_from_file(Path("/path/to/boostrap.json")) unleash_client = UnleashClient( "https://my.unleash.server.com", "HAMSTER_API", cache=my_cache )
- Parameters:
name – Name of cache.
directory – Location to create cache. If empty, will use filecache default.
- bootstrap_from_dict(initial_config: dict) None
Loads initial Unleash configuration from a dictionary.
Note: Pre-seeded configuration will only be used if UnleashClient is initialized with bootstrap=true.
- Parameters:
initial_config – Dictionary that contains initial configuration.
- bootstrap_from_file(initial_config_file: Path) None
Loads initial Unleash configuration from a file.
Note: Pre-seeded configuration will only be used if UnleashClient is initialized with bootstrap=true.
- Parameters:
initial_configuration_file – Path to document containing initial configuration. Must be JSON.
- bootstrap_from_url(initial_config_url: str, headers: dict | None = None, request_timeout: int | None = None) None
Loads initial Unleash configuration from a url.
Note: Pre-seeded configuration will only be used if UnleashClient is initialized with bootstrap=true.
- Parameters:
initial_configuration_url – Url that returns document containing initial configuration. Must return JSON.
headers – Headers to use when GETing the initial configuration URL.
- set(key: str, value: Any)
- mset(data: dict)
- get(key: str, default: Any | None = None)
- exists(key: str)
- destroy()