Skip to content

Instantly share code, notes, and snippets.

@mdippery
Created November 11, 2011 20:06
Show Gist options
  • Save mdippery/1359075 to your computer and use it in GitHub Desktop.
Save mdippery/1359075 to your computer and use it in GitHub Desktop.
Creates a template cache key for Django
from django.utils.hashcompat import md5_constructor
from django.utils.http import urlquote
def template_cache_key(fragment_name, *vary_on):
"""Builds a cache key for a template fragment.
This is shamelessly stolen from Django core.
"""
base_cache_key = "template.cache.%s" % fragment_name
args = md5_constructor(u":".join([urlquote(var) for var in vary_on]))
return "%s.%s" % (base_cache_key, args.hexdigest())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment