deepcave.utils.cache¶
# Cache
This module provides utilities to handle the cache.
This includes reading, writing, set and get utilities, as well as clearing the cache. The cache handles a json file.
- ## Classes
Cache: Cache handles a json file.
Classes
|
Cache handles a json file. |
- class deepcave.utils.cache.Cache(filename=None, defaults=None, debug=False, write_file=True)[source]¶
Bases:
object
Cache handles a json file.
Decided not to use flask_caching since code is easier to change to our needs.
- clear(write_file=True)[source]¶
Clear all cache and reset to defaults.
- Parameters:
write_file (bool, optional) – Whether to write the constant of the cache into a file. Default is True.
- Return type:
None
- get(*keys)[source]¶
Retrieve value for a specific key.
- Parameters:
*keys (str) – The key to retrieve the value from.
- Returns:
The value of the key.
- Return type:
Optional[Any]
- has(*keys)[source]¶
Check whether cache has specific key.
- Parameters:
*keys (str) – The key to check for.
- Returns:
Whether cache has specific key.
- Return type:
bool
- set(*keys, value, write_file=True)[source]¶
Set a value from a chain of keys.
E.g. set(“a”, “b”, “c”, value=4) creates following dictionary: {“a”: {“b”: {“c”: 4}}}
- Parameters:
*keys (str) – The keys to set the value from.
value (Any) – The value to be set.
write_file (bool, optional) – Whether to write the constant of the cache into a file. Default is True.
- Raises:
RuntimeError – If the type of the key is not a string.
- Return type:
None