[Python-ideas] caching properties

Daniel Fetchinson fetchinson at googlemail.com
Thu Apr 30 14:55:41 CEST 2009

>> 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:
> @property
> @cache  # or "once" if you prefer the Eiffel name
> def value(self):
>     pass
> Such a decorator could then be used on any appropriate function, not
> just for properties.

I agree, -1 on modifying @property and +1 on adding a new decorator to
functools or some other module, maybe a collection of useful


Psss, psss, put it down! - http://www.cafepress.com/putitdown

More information about the Python-ideas mailing list