Skip to content

Instantly share code, notes, and snippets.

@gerad
Created September 11, 2009 15:52
Show Gist options
  • Save gerad/185375 to your computer and use it in GitHub Desktop.
Save gerad/185375 to your computer and use it in GitHub Desktop.
memcache wrapper for google appengine
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