autocached

On this page

autocached#

autocached(func)#

Make a method autocached.

When the method is accessed, it will first check if a key with the same name (as the property) exists in the module cache. If yes, it directly returns the cached values, otherwise it runs the code of the method, caches the result and returns it.

There is no check on the module containing a cache. If not it will raise an AttributeError on accessing the method.

This also works for properties. Make sure you autocache the method first:

@property
@autocached
def my_property(self): ...
Parameters:

func (Callable[[T_CachedMod], R])

Return type:

Callable[[T_CachedMod], R]