Skip to content

Instantly share code, notes, and snippets.

@Ignas
Created July 22, 2014 15:10
Show Gist options
  • Save Ignas/e1067afcb9b6b21973ef to your computer and use it in GitHub Desktop.
Save Ignas/e1067afcb9b6b21973ef to your computer and use it in GitHub Desktop.
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