February 2019
Intermediate to advanced
672 pages
16h 50m
English
A simple library that, among other things, provides a simple on-disk cache is joblib. The package can be used in a similar way as lru_cache, except that the results will be stored on disk and will persist between runs.
The joblib module provides the Memory class that can be used to memoize functions using the Memory.cache decorator:
from joblib import Memory memory = Memory(cachedir='/path/to/cachedir') @memory.cache def sum2(a, b): return a + b
The function will behave similar to lru_cache, with the exception that the results will be stored on-disk in the directory specified by the cachedir argument during Memory initialization. Additionally, the cached ...