apeye.cache

Caching functions for functions.

See also

class Cache(app_name)[source]

Bases: object

Cache function arguments to and in-memory dictionary and a JSON file.

Parameters

app_name (str) – The name of the app. This dictates the name of the cache directory.

Methods:

__call__(​func)

Decorator to cache the return values of a function based on its inputs.

clear(​[func])

Clear the cache.

load_cache(​func)

Loads the cache for the given function.

Attributes:

app_name

The name of the app.

cache_dir

The location of the cache directory on disk.

caches

Mapping of function names to their caches.

__call__(func)[source]

Decorator to cache the return values of a function based on its inputs.

Parameters

func (Callable)

app_name

Type:    str

The name of the app. This dictates the name of the cache directory.

cache_dir

Type:    PathPlus

The location of the cache directory on disk.

caches

Type:    Dict[str, Dict[str, Any]]

Mapping of function names to their caches.

clear(func=None)[source]

Clear the cache.

Parameters

func (Optional[Callable]) – Optional function to clear the cache for. By default, the whole cache is cleared.

Return type

bool

Returns

True to indicate success. False otherwise.

load_cache(func)[source]

Loads the cache for the given function.

Parameters

func (Callable)