Last active
December 15, 2015 05:19
-
-
Save codingjester/5208250 to your computer and use it in GitHub Desktop.
Simple to disk filecache for python. Why? Because I needed it now.
This file contains hidden or 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
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