+def cachedproperty(func):
+ name = '__cache_' + func.__name__ + '_' + str(id(func))
+ def getter(self):
+ try:
+ return getattr(self, name)
+ except AttributeError:
+ value = func(self)
+ setattr(self, name, value)
+ return value
+ return property(getter)
+