Created
September 11, 2009 15:52
-
-
Save gerad/185375 to your computer and use it in GitHub Desktop.
memcache wrapper for google appengine
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
def memcache(func): | |
def cached(*args): | |
key = pickle.dumps((func.__name__, args)) | |
cache = Memcache.get(key) | |
if (cache): | |
logging.info("cache hit for %s" % func.__name__) | |
return pickle.loads(cache) | |
value = func(*args) | |
if (value): | |
try: | |
logging.info("caching results for %s" % func.__name__) | |
Memcache.set(key, pickle.dumps(value), 60 * 60 * 24) | |
except: | |
logging.error("FAIL: caching results for %s" % func.__name__) | |
return value | |
return cached |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment