ContextCache

class dnois.utils.ContextCache

A class to enable cacheing return values of its methods. First, decorate the methods that may be cached with context_cache(). Then, start a “with” block with enable_cache() and the specified methods are cached in the block. At the end of the block, the cache is cleared.

Warning

Specified methods are cached unconditionally, i.e. the second call returns what the first call returns exactly.

enable_cache(items: str | Collection[str])

Return a context manager that caches the specified methods.

Parameters:

items – A collection of keys of cached methods.