[Python-ideas] caching properties

Aahz aahz at pythoncraft.com
Fri May 1 03:42:00 CEST 2009


On Thu, Apr 30, 2009, George Sakkis wrote:
> On Thu, Apr 30, 2009 at 7:37 PM, Ben Finney <ben+python at benfinney.id.au> wrote:
>> 
>> I think a memoize decorator (by whatever name) is the right level of
>> generality to address this use case, and has the advantage of existing
>> implementations.
> 
> 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.

Then a full-blown PEP is required.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair



More information about the Python-ideas mailing list