Memoization#
The memoization modules provides standalone memoiziation decorators that create an independent cache object for each decorated function.
- cacheout.memoization.fifo_memoize(maxsize: int = 128, ttl: int | float = 0, typed: bool = False) Callable[[F], F][source]#
- cacheout.memoization.lfu_memoize(maxsize: int = 128, ttl: int | float = 0, typed: bool = False) Callable[[F], F][source]#
- cacheout.memoization.lifo_memoize(maxsize: int = 128, ttl: int | float = 0, typed: bool = False) Callable[[F], F][source]#
- cacheout.memoization.lru_memoize(maxsize: int = 128, ttl: int | float = 0, typed: bool = False) Callable[[F], F][source]#
- cacheout.memoization.memoize(maxsize: int = 128, ttl: int | float = 0, typed: bool = False) Callable[[F], F][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
Cacheand the arguments provided to this decorator followed by an immediate call toCache.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 – Maximum size of cache dictionary. Defaults to
128.ttl – Default TTL for all cache entries. Defaults to
0which means that entries do not expire.typed – Whether to cache arguments of a different type separately. For example,
<function>(1)and<function>(1.0)would be treated differently. Defaults toFalse.