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.- Parameters:
- funcCallable
- Method from which the result should be cached. 
 
- func
- Returns:
- Callable
- Decorated method. 
 
 - 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 the- immutabledecorator, which may not be true of- cached_property.- cached_getterguarantees that the cached value will be stored in an attribute named- _cached_{name-of-decorated-function}. Classes that use- cached_getterare responsible for guaranteeing that this name is not otherwise used, and is included if- __slots__is defined.