hermes.model.hermes_cache
=========================

.. py:module:: hermes.model.hermes_cache


Classes
-------

.. autoapisummary::

   hermes.model.hermes_cache.HermesCache
   hermes.model.hermes_cache.HermesCacheManager


Module Contents
---------------

.. py:class:: 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.

   .. attribute:: _cache_dir

      The directory the cache is located at.

      :type: Path

   .. attribute:: _cached_data

      The cache of the files in the cache. The key is the filename.

      :type: dict[str, Any]


   .. py:method:: __enter__() -> None

      Caches all files in the cache_dir.

      :rtype: None



   .. py:method:: __getitem__(item: str) -> Any

      Loads a file if necessary or returns the cached value.

      :param item: The name of the file.
      :type item: str

      :returns: The JSON value in the given file.
      :rtype: Any



   .. py:method:: __setitem__(key: str, value: Any) -> None

      Writes a value into the cache.

      Note that the files isn't immediately updated only the cache is.

      :param key: The filename the data is written too.
      :type key: str
      :param value: The JSON value for the file.
      :type value: Any

      :rtype: None



   .. py:method:: __exit__(exc_type: Optional[type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[types.TracebackType]) -> None

      Updates the files from the cache.

      :param exc_type: The type of the exception.
      :type exc_type: type[BaseException] | None
      :param exc_val: (BaseException | None): Unused
      :param exc_tb: (TracebackType | None): Unused

      :rtype: None



.. py:class:: HermesCacheManager(project_dir: pathlib.Path = Path.cwd())

   The HermesCacheManager supplies the user with easy access to the HERMES cache.

   .. attribute:: project_dir

      The directory the project is located in.

      :type: Path

   .. attribute:: cache_dir

      The cache directory inside the project_dir.

      :type: Path

   .. attribute:: _current_step

      The list of steps (i.e. cache names).

      :type: list[str]

   .. attribute:: CACHE_DIR_NAME

      (class attribute) The relative directory all HERMES caches are located in.

      :type: str


   .. py:method:: prepare_step(step: str) -> None

      Add another cache dir to the list of steps.

      :param step: The new cache dir.
      :type step: str

      :rtype: None



   .. py:method:: finalize_step(step: str) -> None

      Remove the step from the list of steps if it is the last one.

      :param step: The cache dir that is removed.
      :type step: str

      :rtype: None

      :raises ValueError: If no step can be removed.
      :raises ValueError: If the given step is not the last one.



   .. py:method:: __getitem__(source_name: str) -> HermesCache

      Return the HERMES cache at the current cache dir and the given sub dir (source_name).

      :param source_name: The name of the sub dir of the current cache dir.
      :type source_name: str

      :returns: The HermesCache object of the cache.
      :rtype: HermesCache

      :raises HermesCacheError: If no step has been prepared (i.e. no current cache dir is set).



