Memoization

The memoization modules provides standalone memoiziation decorators that create an independent cache object for each decorated function.

cacheout.memoization.fifo_memoize(maxsize=128, ttl=0, typed=False)[source]

Like memoize() except it uses FIFOCache.

cacheout.memoization.lfu_memoize(maxsize=128, ttl=0, typed=False)[source]

Like memoize() except it uses LFUCache.

cacheout.memoization.lifo_memoize(maxsize=128, ttl=0, typed=False)[source]

Like memoize() except it uses LIFOCache.

cacheout.memoization.lru_memoize(maxsize=128, ttl=0, typed=False)[source]

Like memoize() except it uses LRUCache.

cacheout.memoization.memoize(maxsize=128, ttl=0, typed=False)[source]

Decorator that wraps a function with a memoizing callable and works on both synchronous and asynchronous functions.

A cache object will be created for each memoized function using Cache and the arguments provided to this decorator followed by an immediate call to Cache.memoize() to wrap the function. The cache object can be accessed at <function>.cache. The uncached version (i.e. the original function) can be accessed at <function>.uncached. Each return value from the function will be cached using the function arguments as the cache key.

Parameters:
  • maxsize (int, optional) – Maximum size of cache dictionary. Defaults to 128.
  • ttl (int, optional) – Default TTL for all cache entries. Defaults to 0 which means that entries do not expire.
  • typed (bool, optional) – Whether to cache arguments of a different type separately. For example, <function>(1) and <function>(1.0) would be treated differently. Defaults to False.
cacheout.memoization.mru_memoize(maxsize=128, ttl=0, typed=False)[source]

Like memoize() except it uses MRUCache.

cacheout.memoization.rr_memoize(maxsize=128, ttl=0, typed=False)[source]

Like memoize() except it uses RRCache.