Popular recipes tagged "memoize"http://code.activestate.com/recipes/tags/memoize/popular/2012-01-02T05:53:19-08: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>
Memoize Generator (Python)
2012-01-02T05:53:19-08:00Peter Donishttp://code.activestate.com/recipes/users/4180313/http://code.activestate.com/recipes/577992-memoize-generator/
<p style="color: grey">
Python
recipe 577992
by <a href="/recipes/users/4180313/">Peter Donis</a>
(<a href="/recipes/tags/decorators/">decorators</a>, <a href="/recipes/tags/generators/">generators</a>, <a href="/recipes/tags/memoization/">memoization</a>, <a href="/recipes/tags/memoize/">memoize</a>).
Revision 2.
</p>
<p>A wrapper class for generators that "memoizes" them, so that even
if the generator is realized multiple times, each term only gets
computed once (after that the result is simply returned from a
cache).</p>