pyphi.cache#

Memoization and caching utilities.

Threading#

ContentCache (see pyphi.cache.content) is safe for concurrent use by worker threads: cached values are correct, eviction is sound, and no operation raises under concurrent access. Its hits/misses counters are best-effort under free-threaded Python — exact under the GIL and under process-isolated parallelism, approximate when threads share one cache — since they are diagnostics and are updated outside the lock.

The caches built by the cache decorator below are module-level, so the thread scheduler shares them across worker threads. They follow the same design as ContentCache: the hit path is lock-free, using only atomic dict operations, and admission (which runs the store’s eviction loop) is locked. Their counters carry the same best-effort caveat under free-threading.

Public surface#

  • info(): dict of name -> _CacheInfo across every registered cache.

  • clear_all(): clear every registered in-memory cache. Persistent on-disk stores are skipped; clear those by name.

  • clear(name): clear one cache by name (including persistent ones).

  • register(policy): register a CachePolicy adapter.

  • unregister(name): remove a registration.

See pyphi.cache.policy for the CachePolicy Protocol and pyphi.cache.registry for the registry implementation.

Functions

cache([typed])

Memoization decorator bounded by bytes.

Submodules

cache_utils

Common utilities for caching.

content

Content-addressed cache with refcounted eviction and a byte-weighted bound.

disk

Disk-backed content-addressed store for top-level results.

policy

Cache policy Protocol and adapters.

registry

Process-local registry of cache policies.