On Sat, Sep 4, 2010 at 3:28 AM, Stefan Behnel <stefan...@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
implicit)

widget_cache = lru_cache()
widget_cache[name] = widget

@lru_cache().wrap
def get_thingy(name):
    return something(name)

# get_thingy.cache is an lru_cache instance
print(get_thingy.cache.hits)

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>
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to