mpylab.tools.preflight_cache module

Persistent, content-addressed cache helpers for measurement preflights.

mpylab.tools.preflight_cache.content_fingerprint(value)

Return a deterministic SHA-256 fingerprint for preflight input.

Parameters:

value (object) – Nested scalar, mapping, sequence, set, or path-like input. Mapping and set order do not affect the result, while different container types remain distinguishable.

Returns:

Lowercase hexadecimal SHA-256 digest.

Return type:

str

mpylab.tools.preflight_cache.default_preflight_cache_dir()

Return the user-local mpylab preflight cache directory.

Returns:

Directory selected from MPYLAB_PREFLIGHT_CACHE_DIR, then XDG_CACHE_HOME, or finally the conventional cache directory below the user’s home directory.

Return type:

pathlib.Path

mpylab.tools.preflight_cache.file_fingerprint(path)

Return path-independent content metadata for one dependency file.

Parameters:

path (path-like) – File whose content is part of a preflight dependency set.

Returns:

Basename, byte count, and hexadecimal SHA-256 content digest.

Return type:

dict

mpylab.tools.preflight_cache.load_preflight_cache(cache_dir, namespace, fingerprint)

Load a valid cache record or return None.

Parameters:
  • cache_dir (path-like) – Root cache directory.

  • namespace (str) – Measurement-specific subdirectory.

  • fingerprint (str) – Expected content fingerprint and cache filename stem.

Returns:

Cached payload, or None when the record is absent, corrupt, outdated, or belongs to another fingerprint.

Return type:

object or None

mpylab.tools.preflight_cache.save_preflight_cache(cache_dir, namespace, fingerprint, payload)

Atomically store one cache record and return its final path.

Parameters:
  • cache_dir (path-like) – Root cache directory.

  • namespace (str) – Measurement-specific subdirectory.

  • fingerprint (str) – Content fingerprint used as the cache filename stem.

  • payload (object) – Pickle-compatible data to store.

Returns:

Final cache-record path.

Return type:

pathlib.Path