The library does not seem to support partial cache deletion.
You can split the functino cache into two pairs:
from tempfile import mkdtemp from joblib import Memory memory1 = Memory(cachedir=mkdtemp(), verbose=0) memory2 = Memory(cachedir=mkdtemp(), verbose=0) @memory1.cache def run_my_query1() # run query_1 return df @memory2.cache def run_my_query2() # run query_2 return df
Now you can selectively clear the cache:
memory2.clear()
UPDATE after viewing behzad.nouri's comment:
You can use the call method of the decorated function. But, as you can see in the following example, the return value is different from a regular call. You have to take care of this.
>>> import tempfile >>> import joblib >>> memory = joblib.Memory(cachedir=tempfile.mkdtemp(), verbose=0) >>> @memory.cache ... def run(x): ... print('called with {}'.format(x))
source share