A :func:`property` that is only evaluated once. Subsequent access returns the cached value. Setting the property sets the cached value. Deleting the property clears the cached value, accessing it again will evaluate it again. .. code-block:: python class Example: @cached_property def value(self): # calculate something important here return 42 e = Example() e.value # evaluates e.value # uses cache e.value = 16 # sets cache del e.value # clears cache If the class defines ``__slots__``, it must add ``_cache_{name}`` as a slot. Alternatively, it can add ``__dict__``, but that's usually not desirable. .. versionchanged:: 2.1 Works with ``__slots__``. .. versionchanged:: 2.0 ``del obj.name`` clears the cached value.
Method | __delete__ |
Undocumented |
Method | __get__ |
Undocumented |
Method | __init__ |
Undocumented |
Method | __set__ |
Undocumented |
Instance Variable | __module__ |
Undocumented |
Instance Variable | __name__ |
Undocumented |
Instance Variable | slot |
Undocumented |
t.Callable[ [ t.Any], _T]
, name: t.Optional[ str]
= None, doc: t.Optional[ str]
= None):
(source)
¶
Undocumented