Ticket #5691: cache.patch
File cache.patch, 2.5 KB (added by , 16 years ago) |
---|
-
django/utils/cache.py
29 29 from django.utils.encoding import smart_str, iri_to_uri 30 30 from django.utils.http import http_date 31 31 from django.utils.hashcompat import md5_constructor 32 from django.utils import translation 32 33 33 34 cc_delim_re = re.compile(r'\s*,\s*') 34 35 … … 136 137 if newheader.lower() not in existing_headers] 137 138 response['Vary'] = ', '.join(vary_headers + additional_headers) 138 139 139 def _generate_cache_key(request, headerlist, key_prefix): 140 def _generate_cache_key(request, headerlist, key_prefix): 140 141 """Returns a cache key from the headers given in the header list.""" 141 142 ctx = md5_constructor() 142 143 for header in headerlist: 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 cache_key = 'views.decorators.cache.cache_page.%s.%s.%s' % ( 147 148 key_prefix, iri_to_uri(request.path), ctx.hexdigest()) 148 149 150 if settings.USE_I18N: 151 cache_key += ".%s" % translation.get_language() 152 return cache_key 153 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 … … 155 161 156 162 If there is no headerlist stored, the page needs to be rebuilt, so this 157 163 function returns None. 158 """ 164 """ 159 165 if key_prefix is None: 160 166 key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX 161 167 cache_key = 'views.decorators.cache.cache_header.%s.%s' % ( 162 168 key_prefix, iri_to_uri(request.path)) 169 if settings.USE_I18N: 170 cache_key += ".%s" % translation.get_language() 171 163 172 headerlist = cache.get(cache_key, None) 164 173 if headerlist is not None: 165 174 return _generate_cache_key(request, headerlist, key_prefix) … … 183 192 key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX 184 193 if cache_timeout is None: 185 194 cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS 195 186 196 cache_key = 'views.decorators.cache.cache_header.%s.%s' % ( 187 197 key_prefix, iri_to_uri(request.path)) 198 if settings.USE_I18N: 199 cache_key += ".%s" % translation.get_language() 188 200 if response.has_header('Vary'): 189 201 headerlist = ['HTTP_'+header.upper().replace('-', '_') 190 202 for header in cc_delim_re.split(response['Vary'])]