Caching#

simulate_cached() memoizes recordings to disk, keyed by spec.cache_key(). These helpers locate that cache.

simulate_cached#

minisim.simulate_cached(spec, *, root=None)[source]#

Return the recording for spec, loading from cache or simulating on a miss.

Parameters:
  • spec (Spec) – The recording spec; its cache_key is the cache key.

  • root (str | Path | None) – Cache directory. Defaults to cache_dir() ($MINISIM_CACHE or ~/.cache/minisim).

Return type:

Recording

Notes

The cache is keyed by filename ({cache_key}.zarr): a changed spec serializes to a new key, hence a new filename and a clean miss, so the cache never serves a recording for the wrong spec. A hit is served by Recording.load(); a miss runs simulate() and persists the result with Recording.save() before returning it.

cache_dir#

minisim.cache_dir()[source]#

The resolved cache root: $MINISIM_CACHE if set, else DEFAULT_CACHE_DIR.

The returned path is user-expanded (~) but not created - simulate_cached() makes it on first write.

Return type:

Path

cache_path#

minisim.cache_path(spec, root=None)[source]#

The on-disk path a recording for spec is cached at: {root}/{cache_key}.zarr.

Parameters:
Return type:

Path