Top-rated recipes tagged "functools"http://code.activestate.com/recipes/tags/functools/top/2010-11-04T20:23:35-07:00ActiveState Code RecipesA memoize decorator for instance methods (Python)
2010-11-04T20:23:35-07:00Daniel Millerhttp://code.activestate.com/recipes/users/4016391/http://code.activestate.com/recipes/577452-a-memoize-decorator-for-instance-methods/
<p style="color: grey">
Python
recipe 577452
by <a href="/recipes/users/4016391/">Daniel Miller</a>
(<a href="/recipes/tags/cache/">cache</a>, <a href="/recipes/tags/functools/">functools</a>, <a href="/recipes/tags/memoize/">memoize</a>, <a href="/recipes/tags/partial/">partial</a>).
</p>
<p>A simple result-caching decorator for instance methods. NOTE: does not work with plain old non-instance-method functions. The cache is stored on the instance to prevent memory leaks caused by long-term caching beyond the life of the instance (almost all other recipes I found suffer from this problem when used with instance methods).</p>