pyphi.cache.content#
Content-addressed cache with refcounted eviction and a byte-weighted bound.
Entries are keyed on (fingerprint, args), where fingerprint is a
label-free content digest of a source object (a System or Substrate).
Distinct objects that share a fingerprint share entries. An entry set is
evicted when the last live source object carrying its fingerprint is
garbage-collected, so prompt release is preserved while equivalent objects
reuse results.
A second eviction path bounds occupancy while a source object stays alive: the
entries are held in a ByteBoundedStore, which
holds its byte weight steady once resident memory reaches the cache ceiling and
admits new entries by evicting least recently used ones. Occupancy is measured
in bytes rather than entries because cached repertoires vary in size by orders
of magnitude across purview orders.
Safe for concurrent use by worker threads: cached values are correct, eviction is sound,
and no operation raises under concurrent access. The hits and misses counters are
best-effort under free-threaded Python (exact under the GIL and under process isolation)
— they are diagnostics, updated outside the lock. The tracked byte weight carries the
same caveat: a hit reinserting its entry concurrently with a fingerprint eviction can
leave the weight off by that entry, which shifts where the bound falls without affecting
any cached value. Admission and eviction themselves are locked.
Classes
|