Copyright © 2010-2017, Brendan Doms
Licensed under the MIT license
GAE HTML is a small, simple tool to cache and minify HTML in GAE projects.
It removes comments and whitespace to reduce the amount of data when sending a response. This should not effect validation or content of an HTML document.
Usage is simple. First, import:
from gae_html import cacheAndRender
cacheAndRender
is a decorator to place on an action to skip straight to returning the
cached version of a page, if it exists. Otherwise, it calls the action, takes the result,
caches it, and adds it to the response. For example:
@cacheAndRender()
def get(self):
# do some logic and handling of request
return self.compile("template")
It automatically skips caching in obvious circumstances like during development or if the user is an administrator.
Behavior is controlled through optional keyword arguments:
expires
(int) default: 86400, number of seconds to cache forminify
(bool) default: True, whether to minify or notinclude_comments
(bool) default: False, whether to include comments or not when minifyinguse_datastore
(bool) default: False, whether to use the datastore as a fallback cache or notskip_check
(function(handler)) default: None, if present skips caching when returningTrue
content_type
(string) default: None, if present sets theContent-Type
header
A more complex example that avoids caching when errors are present in a session might look like:
@cacheAndRender(skip_check=lambda handler: 'errors' in handler.session)
def get(self):
# ...
Bug reports, feature requests, and patches are all welcome!