Created
November 8, 2013 12:01
-
-
Save kezabelle/7370050 to your computer and use it in GitHub Desktop.
Sketching out a Django cached Loader which excludes some template patterns ...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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