global_disk_cache#
- tpcp.caching.global_disk_cache(memory: Memory = Memory(location=None), *, cache_only: Sequence[str] | None = None)[source]#
Wrap an algorithm/pipeline class to enable joblib based disk cashing for its primary action method.
This will replace the action of the algorithm with a cached version. We use our knowledge about what is considered a “parameter” of an algorithm to clearly define the inputs of this cached function and avoid potential errors that might occur in a general caching solution.
The cache will be invalidated, if any of the algorithm parameters change.
This function can be used as a decorator on the class directly or called with the class as argument. In both cases the single global class object will be modified. At the moment there is no way of disabling the caching again.
Warning
When using this decorator, all actions calls are not made on the original object, but on a clone, and only the results are “re-attached” to the original object. In case you rely on side effects of the action method, this might cause issues. But, if you are relying on side effects, you are probably doing something wrong anyway.
- Parameters:
- memory
The joblib memory object that is used to cache the results.
Memory(None)
is equivalent to no caching.- cache_only
A list of strings that defines which results should be cached. If None, all results are cached. In case you only cash a subset of the results, only these results will be available on the returned objects. Also, during the first (uncached) call, only the results that are cached will be available. This might be helpful to reduce the size of the cache.
- Returns:
- The algorithm class with the cached action method.
See also
tpcp.caching.global_ram_cache
Same as this function, but uses an LRU cache in RAM instead of a disk cache.