pyphi.cache.cache_utils.ByteBoundedStore#

class pyphi.cache.cache_utils.ByteBoundedStore[source]#

Bases: object

A dict that holds its byte weight steady once memory reaches the ceiling.

Insertion order is the recency order, so the least recently used entry is the first one iteration yields; a caller reinserts an entry on a hit to move it to the recent end. Until resident memory reaches the cache ceiling (see memory_full()) the store grows freely. From then on it admits an entry by evicting least recently used ones, and refuses one too large to fit an empty store rather than flushing everything to hold it.

Eviction holds occupancy steady; it does not reduce resident memory, since freeing a Python object returns its memory to the process allocator for reuse rather than to the operating system.

Not internally synchronized. A caller sharing a store across threads holds its own lock across admit() and discard(); lock-free hits that pop and reinsert entries in data directly are tolerated, and the eviction loop never raises because of them.

property nbytes: int#

Estimated bytes held by this store’s entries.

admit(key, value)[source]#

Store an entry, evicting least recently used ones to make room.

Parameters:
Return type:

None

discard(key)[source]#

Remove an entry if present, crediting back its weight.

Parameters:

key (Any)

Return type:

None