Ticket #5691: django_utils_cache_patch.diff
File django_utils_cache_patch.diff, 2.4 KB (added by , 17 years ago) |
---|
-
django/utils/cache.py
24 24 from django.conf import settings 25 25 from django.core.cache import cache 26 26 from django.utils.encoding import smart_str, iri_to_uri 27 from django.utils import translation 27 28 28 29 cc_delim_re = re.compile(r'\s*,\s*') 29 30 … … 121 122 def _generate_cache_key(request, headerlist, key_prefix): 122 123 "Returns a cache key from the headers given in the header list." 123 124 ctx = md5.new() 125 lang = translation.get_language() 124 126 for header in headerlist: 125 127 value = request.META.get(header, None) 126 128 if value is not None: 127 129 ctx.update(value) 128 return 'views.decorators.cache.cache_page.%s.%s.%s ' % (key_prefix, iri_to_uri(request.path), ctx.hexdigest())130 return 'views.decorators.cache.cache_page.%s.%s.%s_%s' % (key_prefix, iri_to_uri(request.path), ctx.hexdigest(),lang) 129 131 130 132 def get_cache_key(request, key_prefix=None): 131 133 """ … … 137 139 If there is no headerlist stored, the page needs to be rebuilt, so this 138 140 function returns None. 139 141 """ 142 lang = translation.get_language() 140 143 if key_prefix is None: 141 144 key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX 142 cache_key = 'views.decorators.cache.cache_header.%s.%s ' % (key_prefix, iri_to_uri(request.path))145 cache_key = 'views.decorators.cache.cache_header.%s.%s_%s' % (key_prefix, iri_to_uri(request.path),lang) 143 146 headerlist = cache.get(cache_key, None) 144 147 if headerlist is not None: 145 148 return _generate_cache_key(request, headerlist, key_prefix) … … 159 162 cache, this just means that we have to build the response once to get at 160 163 the Vary header and so at the list of headers to use for the cache key. 161 164 """ 165 lang = translation.get_language() 162 166 if key_prefix is None: 163 167 key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX 164 168 if cache_timeout is None: 165 169 cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS 166 cache_key = 'views.decorators.cache.cache_header.%s.%s ' % (key_prefix, iri_to_uri(request.path))170 cache_key = 'views.decorators.cache.cache_header.%s.%s_%s' % (key_prefix, iri_to_uri(request.path),lang) 167 171 if response.has_header('Vary'): 168 172 headerlist = ['HTTP_'+header.upper().replace('-', '_') for header in vary_delim_re.split(response['Vary'])] 169 173 cache.set(cache_key, headerlist, cache_timeout)