Code

Ticket #19510: #19510-thread_safe_template_cache.diff

File #19510-thread_safe_template_cache.diff, 1.4 KB (added by Kronuz, 19 months ago)
Line 
1diff --git a/django/template/loaders/cached.py b/django/template/loaders/cached.py
2index 4c25acd..864b54f 100644
3--- a/django/template/loaders/cached.py
4+++ b/django/template/loaders/cached.py
5@@ -42,7 +42,8 @@ class Loader(BaseLoader):
6             # If template directories were specified, use a hash to differentiate
7             key = '-'.join([template_name, hashlib.sha1('|'.join(template_dirs)).hexdigest()])
8 
9-        if key not in self.template_cache:
10+        template_tuple = self.template_cache.get(key)
11+        if template_tuple is None:
12             template, origin = self.find_template(template_name, template_dirs)
13             if not hasattr(template, 'render'):
14                 try:
15@@ -52,9 +53,10 @@ class Loader(BaseLoader):
16                     # back off to returning the source and display name for the template
17                     # we were asked to load. This allows for correct identification (later)
18                     # of the actual template that does not exist.
19-                    return template, origin
20-            self.template_cache[key] = template
21-        return self.template_cache[key], None
22+                    return template, origin and origin.name
23+            template_tuple = (template, origin and origin.name)
24+            self.template_cache[key] = template_tuple
25+        return template_tuple
26 
27     def reset(self):
28         "Empty the template cache."