Muscat.Helpers.Cache module¶
- CachedResultDecorator(name: str | None = None, path: str | None = None, needDill: bool | None = False)[source]¶
Decorator to add cache capabilities to a function
- Parameters:
name (str) –
- the name associated to the cache, this value is used to build the file name
to store previous computed values. optional, by default None
path (str, optional) – Path to store the cache data, if None, all data is written to a temporary directory, by default None
needDill (bool, optional) – tells the cache that we need dill for pickling object (in the case lambdas are present ) if dill is not present return the original function with no cache
- GetFunctionWithCache(func: Callable, name: str | None = None, path: str | None = None, needDill: bool = False) Callable [source]¶
- Helper function to conserve the output of a function for later invocation
with the same arguments. The function must be a pure function (ie. the function must not rely on any persistent or internal state). The user can use a dummy argument to force the function to be recalculated. All the argument must support the == operator and a sha256 or pickle
- Parameters:
func (Callable) – function to be decorated, must be a pure function
name (str, optional) –
- the name associated to the cache, this value is used to build the file name
to store previous computed values. optional, by default None
path (str, optional) – Path to store the cache data, if None, all data is written to a temporary directory, by default None
needDill (bool, default False) – tells the cache that we need dill for pickling object (in the case lambdas are present ) if dill is not present return the original function with no cache
- Returns:
A function pointer with the same argument as function but, if needDill == True and the module is not available then the original function (func) is returned
- Return type:
Callable
- USE_CACHE: bool = True¶
Disconnect the use of the cache Evaluated at execution time (not at definition) so the user can turn off the use of cache for a single call of a cache function