﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
12831	Use CACHE_MIDDLEWARE_KEY_PREFIX in template cache.	bzed@…	nobody	"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."	Uncategorized	closed	Core (Cache system)	1.1	Normal	fixed		bernd.zeimetz@… andre.cruz@…	Design decision needed	1	0	0	0	0	0
