Skip to content

Instantly share code, notes, and snippets.

@kezabelle
Created November 8, 2013 12:01
Show Gist options
  • Save kezabelle/7370050 to your computer and use it in GitHub Desktop.
Save kezabelle/7370050 to your computer and use it in GitHub Desktop.
Sketching out a Django cached Loader which excludes some template patterns ...
from django.template.loaders import cached
from django.conf import settings
class Loader(cached.Loader):
""" mostly cached loader """
def load_template(self, template_name, template_dirs=None, exclusions=None):
if exclusions is None:
exclusions = getattr(settings, 'MOSTLYCACHED_EXCLUDES', ())
template_instance, origin = super(Loader, self).load_template(
template_name=template_name, template_dirs=template_dirs)
for regex in exclusions:
if re.match(regex, template_name) and key in self.template_cache:
del self.template_cache[key]
break
return template_instance, origin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment