Skip to content

Instantly share code, notes, and snippets.

@balazs-endresz
Created March 13, 2015 22:23
Show Gist options
  • Save balazs-endresz/592913a3f425509d3a51 to your computer and use it in GitHub Desktop.
Save balazs-endresz/592913a3f425509d3a51 to your computer and use it in GitHub Desktop.
invalidate cached template fragments (tested with django 1.5 only)
from django.core.cache import cache
from django.utils.hashcompat import md5_constructor
from django.utils.http import urlquote
def invalidate_template_fragment(fragment_name, *variables):
args = md5_constructor(u':'.join([urlquote(var) for var in variables]))
cache_key = 'template.cache.{0}.{1}'.format(fragment_name, args.hexdigest())
cache.delete(cache_key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment