PyDocs

Nav

Functional Programming Modules

cached_property

functools

decorator · Added in 3.8 (source)
  • @cached_property(func)
Transform a method of a class into a property whose value is computed once and then cached as a normal attribute for the life of the instance. Similar to @property, with the addition of caching. Useful for expensive computed properties of instances that are otherwise effectively immutable.
Changed in 3.12
  • 3.12: Prior to Python 3.12, @cached_property included an undocumented lock to ensure that in multi-threaded usage the getter function was guaranteed to run only once per instance. However, the lock was per-property, not per-instance, which could result in unacceptably high lock contention. In Python 3.12+ this locking is removed.
0 Examples
No examples for functools/cached_property.
See Also
No see-alsos for functools/cached_property
0 Notes
No notes for cached_property