Ticket #19511: #19510-thread_safe_template_cache.diff

File #19510-thread_safe_template_cache.diff, 1.4 KB (added by German M. Bravo, 11 years ago)
  • django/template/loaders/cached.py

    diff --git a/django/template/loaders/cached.py b/django/template/loaders/cached.py
    index 4c25acd..864b54f 100644
    a b class Loader(BaseLoader):  
    4242            # If template directories were specified, use a hash to differentiate
    4343            key = '-'.join([template_name, hashlib.sha1('|'.join(template_dirs)).hexdigest()])
    4444
    45         if key not in self.template_cache:
     45        template_tuple = self.template_cache.get(key)
     46        if template_tuple is None:
    4647            template, origin = self.find_template(template_name, template_dirs)
    4748            if not hasattr(template, 'render'):
    4849                try:
    class Loader(BaseLoader):  
    5253                    # back off to returning the source and display name for the template
    5354                    # we were asked to load. This allows for correct identification (later)
    5455                    # of the actual template that does not exist.
    55                     return template, origin
    56             self.template_cache[key] = template
    57         return self.template_cache[key], None
     56                    return template, origin and origin.name
     57            template_tuple = (template, origin and origin.name)
     58            self.template_cache[key] = template_tuple
     59        return template_tuple
    5860
    5961    def reset(self):
    6062        "Empty the template cache."
Back to Top