Ticket #5691: i18n_cache_keys_r7960_t5691.diff
File i18n_cache_keys_r7960_t5691.diff, 2.7 KB (added by , 16 years ago) |
---|
-
django/utils/cache.py
29 29 from django.core.cache import cache 30 30 from django.utils.encoding import smart_str, iri_to_uri 31 31 from django.utils.http import http_date 32 from django.utils import translation 32 33 33 34 cc_delim_re = re.compile(r'\s*,\s*') 34 35 … … 143 144 value = request.META.get(header, None) 144 145 if value is not None: 145 146 ctx.update(value) 146 return 'views.decorators.cache.cache_page.%s.%s.%s' % ( 147 key_prefix, iri_to_uri(request.path), ctx.hexdigest()) 148 147 if settings.USE_I18N: 148 lang = translation.get_language() 149 return 'views.decorators.cache.cache_page.%s.%s.%s.%s' % ( 150 key_prefix, iri_to_uri(request.path), ctx.hexdigest(), lang) 151 else: 152 return 'views.decorators.cache.cache_page.%s.%s.%s' % ( 153 key_prefix, iri_to_uri(request.path), ctx.hexdigest()) 154 149 155 def get_cache_key(request, key_prefix=None): 150 156 """ 151 157 Returns a cache key based on the request path. It can be used in the … … 158 164 """ 159 165 if key_prefix is None: 160 166 key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX 161 cache_key = 'views.decorators.cache.cache_header.%s.%s' % ( 162 key_prefix, iri_to_uri(request.path)) 167 if settings.USE_I18N: 168 lang = translation.get_language() 169 cache_key = 'views.decorators.cache.cache_header.%s.%s.%s' % ( 170 key_prefix, iri_to_uri(request.path), lang) 171 else: 172 cache_key = 'views.decorators.cache.cache_header.%s.%s' % ( 173 key_prefix, iri_to_uri(request.path)) 163 174 headerlist = cache.get(cache_key, None) 164 175 if headerlist is not None: 165 176 return _generate_cache_key(request, headerlist, key_prefix) … … 183 194 key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX 184 195 if cache_timeout is None: 185 196 cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS 186 cache_key = 'views.decorators.cache.cache_header.%s.%s' % ( 187 key_prefix, iri_to_uri(request.path)) 197 if settings.USE_I18N: 198 lang = translation.get_language() 199 cache_key = 'views.decorators.cache.cache_header.%s.%s.%s' % ( 200 key_prefix, iri_to_uri(request.path), lang) 201 else: 202 cache_key = 'views.decorators.cache.cache_header.%s.%s' % ( 203 key_prefix, iri_to_uri(request.path)) 188 204 if response.has_header('Vary'): 189 205 headerlist = ['HTTP_'+header.upper().replace('-', '_') 190 206 for header in cc_delim_re.split(response['Vary'])]