[Python-ideas] caching properties

Steven D'Aprano steve at pearwood.info
Thu Apr 30 05:57:07 CEST 2009

On Thu, 30 Apr 2009 08:33:27 am Benjamin Peterson wrote:
> I think it would be nice to add a "cache" argument to the
> property() constructor. When "cache" was True, property would only
> ask the getter function once for the result. This would simplify
> properties that require expensive operations to compute.

-1 on an extra parameter to property.

+1 on a cache decorator.

It is clear and simple enough to write something like:

@cache  # or "once" if you prefer the Eiffel name
def value(self):

Such a decorator could then be used on any appropriate function, not 
just for properties.

Steven D'Aprano 

More information about the Python-ideas mailing list