pyphi.cache.cache#

pyphi.cache.cache(typed=False)[source]#

Memoization decorator bounded by bytes.

Arguments to the cached function must be hashable. Entries are held in a pyphi.cache.cache_utils.ByteBoundedStore, so the cache grows freely until resident memory reaches the configured ceiling and then holds its occupancy steady, evicting least recently used entries to admit new ones.

The bound is on bytes rather than on entry count because a cached value may be anything from a scalar to an array whose size grows exponentially in the size of the system.

Parameters:

typed (bool, optional) – If True, arguments of different types are cached separately: for example, f(3.0) and f(3) are treated as distinct calls with distinct results. Defaults to False.

Notes

The decorated function exposes cache_info(), which returns a (hits, misses, currsize, nbytes, evictions) named tuple; cache_clear(), which empties the cache and resets its statistics; and __wrapped__, the underlying function.