cache
¶
Memoization and caching utilities.
- pyphi.cache.memory_full()¶
Check if the memory is too full for further caching.
- pyphi.cache.cache(cache={}, maxmem=50, typed=False)¶
Memory-limited cache decorator.
maxmem
is a float between 0 and 100, inclusive, specifying the maximum percentage of physical memory that the cache can use.If
typed
isTrue
, arguments of different types will be cached separately. For example, f(3.0) and f(3) will be treated as distinct calls with distinct results.Arguments to the cached function must be hashable.
View the cache statistics named tuple (hits, misses, currsize) with f.cache_info(). Clear the cache and statistics with f.cache_clear(). Access the underlying function with f.__wrapped__.
- class pyphi.cache.DictCache¶
A generic dictionary-based cache.
Intended to be used as an object-level cache of method results.
- clear()¶
- size()¶
Number of items in cache
- info()¶
Return info about cache hits, misses, and size
- get(key)¶
Get a value out of the cache.
Returns None if the key is not in the cache. Updates cache statistics.
- set(key, value)¶
Set a value in the cache
- key(*args, _prefix=None, **kwargs)¶
Get the cache key for the given function args.
- Kwargs:
prefix: A constant to prefix to the key.
- pyphi.cache.redis_init(db)¶
- pyphi.cache.redis_available()¶
Check if the Redis server is connected.
- class pyphi.cache.RedisCache¶
- clear()¶
Flush the cache.
- static size()¶
Size of the Redis cache.
Note
This is the size of the entire Redis database.
- info()¶
Return cache information.
Note
This is not the cache info for the entire Redis key space.
- get(key)¶
Get a value from the cache.
Returns None if the key is not in the cache.
- set(key, value)¶
Set a value in the cache.
- key()¶
Delegate to subclasses.
- pyphi.cache.validate_parent_cache(parent_cache)¶
- class pyphi.cache.PurviewCache¶
A network-level cache for possible purviews.
- set(key, value)¶
Only set if purview caching is enabled
- pyphi.cache.method(cache_name, key_prefix=None)¶
Caching decorator for object-level method caches.
Cache key generation is delegated to the cache.
- Parameters:
cache_name (str) – The name of the (already-instantiated) cache on the decorated object which should be used to store results of this method.
*key_prefix – A constant to use as part of the cache key in addition to the method arguments.