[Python-Dev] new LRU cache API in Py3.2

Daniel Stutzbach daniel at stutzbachenterprises.com
Sat Sep 4 16:21:25 CEST 2010

On Sat, Sep 4, 2010 at 3:28 AM, Stefan Behnel <stefan_ml at behnel.de> wrote:

> What about adding an intermediate namespace called "cache", so that the new
> operations are available like this:

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

widget_cache = lru_cache()
widget_cache[name] = widget

def get_thingy(name):
    return something(name)

# get_thingy.cache is an lru_cache instance

I have been using a similar LRU cache class to store items retrieved from a
database.  In my case, a decorator-paradigm wouldn'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.
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20100904/52e44afc/attachment.html>

More information about the Python-Dev mailing list