Skip to content

Instantly share code, notes, and snippets.

@codingjester
Last active December 15, 2015 05:19
Show Gist options
  • Save codingjester/5208250 to your computer and use it in GitHub Desktop.
Save codingjester/5208250 to your computer and use it in GitHub Desktop.
Simple to disk filecache for python. Why? Because I needed it now.
import json
import stat
DEBUG = True
def debug_cache_data(fn):
def cache_data(*args):
if DEBUG and os.path.exists(fn.__name__):
return json.loads(open(fn.__name__, 'r').read())
else:
data = fn(*args)
if DEBUG:
open(fn.__name__, 'w').write(json.dumps(data))
return data
return cache_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment