DiskCache

class hmf.core.cache.DiskCache(*, directory=NOTHING)[source]

Where, and whether, to keep Boltzmann-code output on disk.

Pass one as the disk_cache of a Transfer or Growth stage. See the module documentation for the key and the guarantees.

Parameters:

directory (Path, default computed) – The cache directory. Defaults to $HMF_CACHE_DIR, or the platform’s user cache directory for hmf (see default_cache_dir). It is created when the first entry is written.

Attributes

directory: Path

Methods

classmethod fields_info() → tuple[FieldInfo, ...]

Describe this class’s fields, without creating an instance.

Returns:

The name, type, default and documentation of each field.

Return type:

tuple of FieldInfo

load(key: str) → dict[str, ndarray[tuple[Any, ...], dtype[Any]]] | None[source]

Load the arrays stored under key.

Parameters:

key – The content hash of the entry.

Returns:

The arrays by name, or None if there is no (readable) entry.

Return type:

dict or None

path(key: str) → Path[source]

The file holding the entry with content hash key.

Parameters:

key – The content hash of the entry.

Returns:

The path of the file (which may not exist).

Return type:

pathlib.Path

store(key: str, arrays: Mapping[str, ArrayLike]) → Path[source]

Store arrays under key, atomically.

Parameters:
  • key – The content hash.

  • arrays – Arrays by name.

Returns:

The file written.

Return type:

pathlib.Path