cached_property_based_on#
- sunpy.util.cached_property_based_on(attr_name)[source]#
A decorator to cache the value of a property based on the output of a different class attribute.
This decorator caches the values of
getattr(instance, method)
andprop(instance)
. When the decorated property is accessed,getattr(instance, method)
is called. If this returns the same as its cached value, the cached value ofprop
is returned. Otherwise bothmeth
andprop
are recomputed, cached, and the new value ofprop
is returned.- Parameters:
attr_name – The name of the attribute, on which changes are checked for. The actual attribute is accessed using
getattr(attr_name, instance)
.
Notes
The cached value of
meth(instance)
is stored under the keymeth.__name__
.