Skip to content

Instantly share code, notes, and snippets.

@bruntonspall
Created February 23, 2010 12:33
Show Gist options
  • Save bruntonspall/312131 to your computer and use it in GitHub Desktop.
Save bruntonspall/312131 to your computer and use it in GitHub Desktop.
def cached(name, timeout=60):
def wrapper(method):
@functools.wraps(method)
def wrapper(self, *args, **kwargs):
data = memcache.get(name)
if not data:
logging.info("CACHE MISS for "+name)
data = method(self, *args, **kwargs)
memcache.set(name, data, timeout)
return data
return wrapper
return wrapper
def set_content_type(content_type):
def wrapper(method):
@functools.wraps(method)
def wrapper(self, *args, **kwargs):
self.response.headers["Content-Type"] = content_type
return method(self, *args, **kwargs)
return wrapper
return wrapper
def write_response(method):
@functools.wraps(method)
def wrapper(self, *args, **kwargs):
self.response.out.write(method(self, *args, **kwargs))
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment