![]() |
App Engine Python SDK
v1.6.9 rev.445
The Python runtime is available as an experimental Preview feature.
|
Functions | |
def | patch_cache_control |
def | get_max_age |
def | patch_response_headers |
def | add_never_cache_headers |
def | patch_vary_headers |
def | has_vary_header |
def | get_cache_key |
def | learn_cache_key |
Variables | |
tuple | cc_delim_re = re.compile(r'\s*,\s*') |
This module contains helper functions for controlling caching. It does so by managing the "Vary" header of responses. It includes functions to patch the header of response objects directly and decorators that change functions to do that header-patching themselves. For information on the Vary header, see: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.44 Essentially, the "Vary" HTTP header defines which headers a cache should take into account when building its cache key. Requests with the same path but different header content for headers named in "Vary" need to get different cache keys to prevent delivery of wrong content. An example: i18n middleware would need to distinguish caches by the "Accept-language" header.
def google.appengine._internal.django.utils.cache.add_never_cache_headers | ( | response | ) |
Adds headers to a response to indicate that a page should never be cached.
def google.appengine._internal.django.utils.cache.get_cache_key | ( | request, | |
key_prefix = None |
|||
) |
Returns a cache key based on the request path. It can be used in the request phase because it pulls the list of headers to take into account from the global path registry and uses those to build a cache key to check against. If there is no headerlist stored, the page needs to be rebuilt, so this function returns None.
def google.appengine._internal.django.utils.cache.get_max_age | ( | response | ) |
Returns the max-age from the response Cache-Control header as an integer (or ``None`` if it wasn't found or wasn't an integer.
def google.appengine._internal.django.utils.cache.has_vary_header | ( | response, | |
header_query | |||
) |
Checks to see if the response has a given header name in its Vary header.
def google.appengine._internal.django.utils.cache.learn_cache_key | ( | request, | |
response, | |||
cache_timeout = None , |
|||
key_prefix = None |
|||
) |
Learns what headers to take into account for some request path from the response object. It stores those headers in a global path registry so that later access to that path will know what headers to take into account without building the response object itself. The headers are named in the Vary header of the response, but we want to prevent response generation. The list of headers to use for cache key generation is stored in the same cache as the pages themselves. If the cache ages some data out of the cache, this just means that we have to build the response once to get at the Vary header and so at the list of headers to use for the cache key.
def google.appengine._internal.django.utils.cache.patch_cache_control | ( | response, | |
kwargs | |||
) |
This function patches the Cache-Control header by adding all keyword arguments to it. The transformation is as follows: * All keyword parameter names are turned to lowercase, and underscores are converted to hyphens. * If the value of a parameter is True (exactly True, not just a true value), only the parameter name is added to the header. * All other parameters are added with their value, after applying str() to it.
def google.appengine._internal.django.utils.cache.patch_response_headers | ( | response, | |
cache_timeout = None |
|||
) |
Adds some useful headers to the given HttpResponse object: ETag, Last-Modified, Expires and Cache-Control Each header is only added if it isn't already set. cache_timeout is in seconds. The CACHE_MIDDLEWARE_SECONDS setting is used by default.
def google.appengine._internal.django.utils.cache.patch_vary_headers | ( | response, | |
newheaders | |||
) |
Adds (or updates) the "Vary" header in the given HttpResponse object. newheaders is a list of header names that should be in "Vary". Existing headers in "Vary" aren't removed.