libutilitaspy.aspects.memoizer

This module implements a general Memoizer aspect for memoizing (caching) method results.

@author Ernesto Posse

class libutilitaspy.aspects.memoizer.Memoizer[source]

A memoizer aspect decorates methods with actions to remember previously computed values for the methods and the given arguments to avoid recomputing them.

Warning: it is not thread-safe, therefore if a method is executed in multiple threads, the cached results may be inconsistent.

before(klass, method, obj, *args, **kwargs)[source]

Try to return the previously computed value for the method, the given object and given arguments, if it has already been computed and stored in the cache table. If it has not been computed, create a new entry in the cache table for the method, the given object and given arguments.

after(klass, method, obj, retval, exc_type, exc_val, traceback)[source]

Store the return value of the method in the cache table.

Previous topic

libutilitaspy.aspects.logger

Next topic

testing package

This Page