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
selfas 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 theimmutabledecorator, which may not be true ofcached_property.cached_getterguarantees that the cached value will be stored in an attribute named_cached_{name-of-decorated-function}. Classes that usecached_getterare responsible for guaranteeing that this name is not otherwise used, and is included if__slots__is defined.