Skip to content

Instantly share code, notes, and snippets.

@nashibao
Created April 9, 2012 04:33
Show Gist options
  • Save nashibao/2341444 to your computer and use it in GitHub Desktop.
Save nashibao/2341444 to your computer and use it in GitHub Desktop.
django cache key
def _generate_cache_key(request, headerlist, key_prefix):
"""Returns a cache key from the headers given in the header list."""
ctx = md5_constructor()
for header in headerlist:
value = request.META.get(header, None)
if value is not None:
ctx.update(value)
path = md5_constructor(iri_to_uri(request.path))
cache_key = 'views.decorators.cache.cache_page.%s.%s.%s' % (
key_prefix, path.hexdigest(), ctx.hexdigest())
return _i18n_cache_key_suffix(request, cache_key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment