#12831: Use CACHE_MIDDLEWARE_KEY_PREFIX in template cache.
-----------------------------+----------------------------------------------
Reporter: [email protected] | Owner: nobody
Status: new | Milestone:
Component: Cache system | Version: 1.1
Keywords: | Stage: Unreviewed
Has_patch: 1 |
-----------------------------+----------------------------------------------
Running two django instances with the same memcached as cache
backend might result in displaying the wrong template from the cache
in case we have template files with the same name but a different
content.
{{{
ba95e1ae8fb810bbc4e9a2579cff3620df7300f5
diff --git a/Django-1.1.1/django/templatetags/cache.py
b/Django-1.1.1/django/templatetags/cache.py
index 387dd87..6392731 100644
--- a/Django-1.1.1/django/templatetags/cache.py
+++ b/Django-1.1.1/django/templatetags/cache.py
@@ -1,3 +1,4 @@
+from django.conf import settings
from django.template import Library, Node, TemplateSyntaxError, Variable,
VariableDoesNotExist
from django.template import resolve_variable
from django.core.cache import cache
@@ -13,6 +14,7 @@ class CacheNode(Node):
self.expire_time_var = Variable(expire_time_var)
self.fragment_name = fragment_name
self.vary_on = vary_on
+ self.key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
def render(self, context):
try:
@@ -25,7 +27,7 @@ class CacheNode(Node):
raise TemplateSyntaxError('"cache" tag got a non-integer
timeout value: %r' % expire_time)
# Build a unicode key for this fragment and all vary-on's.
args = md5_constructor(u':'.join([urlquote(resolve_variable(var,
context)) for var in self.vary_on]))
- cache_key = 'template.cache.%s.%s' % (self.fragment_name,
args.hexdigest())
+ cache_key = 'template.cache.%s.%s.%s' % (self.key_prefix,
self.fragment_name, args.hexdigest())
value = cache.get(cache_key)
if value is None:
value = self.nodelist.render(context)
}}}
As various other applications which use the caching functions of django
might run into the same issue, it could make sense to add the
CACHE_MIDDLEWARE_KEY_PREFIX to the key at a different place, next to the
backend so all keys of the instance will use it.
--
Ticket URL: <http://code.djangoproject.com/ticket/12831>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.