Skip to content

Instantly share code, notes, and snippets.

@JohannesBuchner
Last active December 17, 2015 13:39
Show Gist options
  • Save JohannesBuchner/5619297 to your computer and use it in GitHub Desktop.
Save JohannesBuchner/5619297 to your computer and use it in GitHub Desktop.
joblib caching for expensive functions
import joblib
import os
cachedir = 'cache'
if not os.path.isdir(cachedir): os.mkdir(cachedir)
mem = joblib.Memory(cachedir=cachedir, verbose=True)
@mem.cache
def my_long_function(i):
return i + i
# first call is done normally
print my_long_function(1)
# second call is loaded from cache directory
print my_long_function(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment