Tools: Caching#
Decorators for memoization/caching.
- tad_mctc.tools.caching.memoize(fcn)[source]#
Memoization decorator that writes the cache to the object itself, hence not allowing the specification of __slots__. It works with and without function arguments.
Note that lru_cache can produce memory leaks for a method.
- Parameters:
fcn (Callable[[Any], T]) – Function to memoize
- Returns:
Memoized function.
- Return type:
Callable[[Any], T]
- tad_mctc.tools.caching.memoize_all_instances(fcn)[source]#
Memoization with shared cache among all instances of the decorated function. This decorator allows specification of __slots__. It works with and without function arguments.
Note that lru_cache can produce memory leaks for a method.
- Parameters:
fcn (Callable[[Any], T]) – Function to memoize
- Returns:
Memoized function.
- Return type:
Callable[[Any], T]