<div class="gmail_quote">On Sat, Sep 4, 2010 at 3:28 AM, Stefan Behnel <span dir="ltr">&lt;<a href="mailto:stefan_ml@behnel.de">stefan_ml@behnel.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
What about adding an intermediate namespace called &quot;cache&quot;, so that the new operations are available like this:<br></blockquote><div><br>I had been thinking that the lru_cache should be a class (with a dict-like interface), so it can be used explicitly and not just as a decorator.  It could provide a wrap() method to be used as a decorator (or implement __call__ to keep the current semantics, but explicit is better than implicit)<br>
<br>widget_cache = lru_cache()<br>widget_cache[name] = widget<br><br>@lru_cache().wrap<br>def get_thingy(name):<br>    return something(name)<br><br> # get_thingy.cache is an lru_cache instance<br>print(get_thingy.cache.hits) <br>
<br>I have been using a similar LRU cache class to store items retrieved from a database.  In my case, a decorator-paradigm wouldn&#39;t work well because I only want to cache a few of the columns from a much larger query, plus there are multiple functions that want to talk to the cache.<br>
</div></div><div style="margin: 2em 0pt;" name="sig_2341e11ee1">--<br>
Daniel Stutzbach, Ph.D.<br>
President, <a href="http://stutzbachenterprises.com">Stutzbach Enterprises, LLC</a>
</div>