cached function

(Shortest import: from brian2.utils.caching import cached)

brian2.utils.caching.cached(func)[source]

Decorator to cache a function so that it will not be re-evaluated when called with the same arguments. Uses the _hashable function to make arguments usable as a dictionary key even though they mutable (lists, dictionaries, etc.).

Parameters:

func : function

The function to decorate.

Returns:

decorated : function

The decorated function.

Notes

This is not a general-purpose caching decorator in any way comparable to functools.lru_cache or joblib’s caching functions. It is very simplistic (no maximum cache size, no normalization of calls, e.g. foo(3) and foo(x=3) are not considered equivalent function calls) and makes very specific assumptions for our use case. Most importantly, Variable objects are considered to be identical when they refer to the same object, even though the actually stored values might have changed.