juju_verify.utils.cache module

Helper function to manage cache.

class juju_verify.utils.cache.Cache(maxsize: int)

Bases: object

Cache for storing outputs using specific keys.

Usage example: cache = Cache()

def run_action(name: str) -> Any:
if name in cache:

return cache[name]

return _run_action(name)

run_action(‘test’) # action ‘test’ is executed run_action(‘test’) # action ‘test’ is not executed run_action(‘test’) # action ‘test’ is not executed

clear() None

Clear cached data.

property keys: List[Any]

Return cached keys.

class juju_verify.utils.cache.CacheManager(enabled: bool = True)

Bases: object

A cache manager that determines when to use this cache.

Usage example: cache_manager = CacheManager(enabled=True) cache = Cache()

def run_action(name: str) -> Any:
if cache_manager.active and name in cache:

return cache[name]

return _run_action(name)

run_action(‘test’) # action ‘test’ is executed run_action(‘test’) # action ‘test’ is not executed

with cache_manager(use_cache=False):

run_action(‘test’) # action ‘test’ is executed

run_action(‘test’) # action ‘test’ is not executed

property active: bool

Return True if cache is activated.

cache_contextmanager(use_cache: bool) Generator

Possibility to temporarily run the cache.

disable() None

Disable the cache.

enable() None

Enable the cache.

property enabled: bool

Return True if cache is enabled.