hermes.model.hermes_cache
Classes
The HermesCache supplies the user with easy (read and write) access to the JSON files in the cache. |
|
The HermesCacheManager supplies the user with easy access to the HERMES cache. |
Module Contents
- class hermes.model.hermes_cache.HermesCache(cache_dir: pathlib.Path)
The HermesCache supplies the user with easy (read and write) access to the JSON files in the cache.
A HermesCache object should only be obtained from an HermesCacheManager object because this ensures the correct cache directory is used.
- __getitem__(item: str) Any
Loads a file if necessary or returns the cached value.
- Parameters:
item (str) – The name of the file.
- Returns:
The JSON value in the given file.
- Return type:
Any
- __setitem__(key: str, value: Any) None
Writes a value into the cache.
Note that the files isn’t immediately updated only the cache is.
- Parameters:
key (str) – The filename the data is written too.
value (Any) – The JSON value for the file.
- Return type:
None
- __exit__(exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None) None
Updates the files from the cache.
- Parameters:
exc_type (type[BaseException] | None) – The type of the exception.
exc_val – (BaseException | None): Unused
exc_tb – (TracebackType | None): Unused
- Return type:
None
- class hermes.model.hermes_cache.HermesCacheManager(project_dir: pathlib.Path = Path.cwd())
The HermesCacheManager supplies the user with easy access to the HERMES cache.
- prepare_step(step: str) None
Add another cache dir to the list of steps.
- Parameters:
step (str) – The new cache dir.
- Return type:
None
- finalize_step(step: str) None
Remove the step from the list of steps if it is the last one.
- Parameters:
step (str) – The cache dir that is removed.
- Return type:
None
- Raises:
ValueError – If no step can be removed.
ValueError – If the given step is not the last one.
- __getitem__(source_name: str) HermesCache
Return the HERMES cache at the current cache dir and the given sub dir (source_name).
- Parameters:
source_name (str) – The name of the sub dir of the current cache dir.
- Returns:
The HermesCache object of the cache.
- Return type:
- Raises:
HermesCacheError – If no step has been prepared (i.e. no current cache dir is set).