[Python-ideas] caching properties

Steven D'Aprano steve at pearwood.info
Fri May 1 04:20:10 CEST 2009


On Fri, 1 May 2009 10:16:11 am George Sakkis wrote:

> IMHO no existing implementation is good enough for addition to the
> standard library. Off the top of my head, some of the issues a
> general and robust implementation should address are:
> - Non hashable parameters.
> - Caching keys based on a subset of the provided parameters (or
> perhaps more general a key function).
> - Bounded-length caches.
> - Different expiration policies for bounded-length caches.
> - As good performance as possible given the previous constraints.
>
> Of course one can write a vanilla version in a few lines, and indeed
> searching for "memoize" in code.activestate.com returns no less than
> 125 results (including one I posted 4.5 years ago). I think the sheer
> number of the posted recipes is an indication that none of them has
> "solved" the problem for good, otherwise people would just reuse it
> instead of keep posting alternatives.

Or people just like re-inventing the wheel.

By all means go ahead and write a PEP and develop an heavyweight "deal 
with everything including the kitchen sink" solution. But in the 
meantime, the standard library could do with a couple of nice, simple, 
lightweight memoize decorators.



-- 
Steven D'Aprano



More information about the Python-ideas mailing list