nlpstack.common.cacheutil module#

nlpstack.common.cacheutil.cached_property(func, **kwargs)[source]#

A decorator that converts a method into a lazy property. The method wrapped is called the first time to retrieve the result and then that calculated result is used the next time you access the value. The result is cached at the method level not at the instance level as in functools.cached_property.

This implementation mimics a part of functools.cached_property but without caching at the instance level, which might be useful in certain scenarios where you don’t want cache to be tied with instance lifecycle.

Parameters:
  • func (Callable[[Any], TypeVar(T)]) – The function to be decorated.

  • kwargs (Any) –

Returns:

A property that represents func as a cached property.

Return type:

property