[Python-ideas] caching properties
Steven D'Aprano
steve at pearwood.info
Fri May 1 04:18:05 CEST 2009
On Fri, 1 May 2009 09:27:13 am George Sakkis wrote:
> I think It's clear by now that caching in the general case is not
> trivial, both in terms of API and implementation. That makes the
> original request - caching properties only - more appealing since
> most problems go away if there are no parameters.
>
> In the simplest case where cache expiration is not supported,
> cachedproperty can be a 7-line decorator:
[snip]
In my opinion, properties aren't special enough to need a special
cachedproperty() decorator. Especially not get-only properties that
never expire, since they're just a function taking a single argument
that returns a constant result. A generic cache that runs on any
function should be sufficient, and more useful than one that is
specific to properties. Properties are not the only application for
caching expensive function calls that never change.
--
Steven D'Aprano
More information about the Python-ideas
mailing list