cached_getter¶
-
lsst.utils.classes.
cached_getter
(func: Callable[[_S], _R]) → Callable[[_S], _R]¶ Decorate a method to cache the result.
Only works on methods that take only
self
as an argument, and returns the cached result on subsequent calls.Notes
This is intended primarily as a stopgap for Python 3.8’s more sophisticated
functools.cached_property
, but it is also explicitly compatible with theimmutable
decorator, which may not be true ofcached_property
.cached_getter
guarantees that the cached value will be stored in an attribute named_cached_{name-of-decorated-function}
. Classes that usecached_getter
are responsible for guaranteeing that this name is not otherwise used, and is included if__slots__
is defined.