Created
July 22, 2014 15:10
-
-
Save Ignas/e1067afcb9b6b21973ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hacky_cache(fn): | |
def caching_runner(): | |
cache_file = '{}.pickle'.format(fn.__name__) | |
if os.path.exists(cache_file): | |
with open(cache_file) as f: | |
return pickle.load(f) | |
else: | |
result = fn() | |
with open(cache_file, 'wb') as f: | |
pickle.dump(result, f) | |
return result | |
return caching_runner |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment