Ticket #4992: cache_by_request_full_path.diff
File cache_by_request_full_path.diff, 3.9 KB (added by , 16 years ago) |
---|
-
django/utils/cache.py
144 144 if value is not None: 145 145 ctx.update(value) 146 146 return 'views.decorators.cache.cache_page.%s.%s.%s' % ( 147 key_prefix, iri_to_uri(request. path), ctx.hexdigest())147 key_prefix, iri_to_uri(request.get_full_path()), ctx.hexdigest()) 148 148 149 149 def get_cache_key(request, key_prefix=None): 150 150 """ 151 Returns a cache key based on the request path . It can be used in the151 Returns a cache key based on the request path and query. It can be used in the 152 152 request phase because it pulls the list of headers to take into account 153 153 from the global path registry and uses those to build a cache key to check 154 154 against. … … 159 159 if key_prefix is None: 160 160 key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX 161 161 cache_key = 'views.decorators.cache.cache_header.%s.%s' % ( 162 key_prefix, iri_to_uri(request. path))162 key_prefix, iri_to_uri(request.get_full_path())) 163 163 headerlist = cache.get(cache_key, None) 164 164 if headerlist is not None: 165 165 return _generate_cache_key(request, headerlist, key_prefix) … … 184 184 if cache_timeout is None: 185 185 cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS 186 186 cache_key = 'views.decorators.cache.cache_header.%s.%s' % ( 187 key_prefix, iri_to_uri(request. path))187 key_prefix, iri_to_uri(request.get_full_path())) 188 188 if response.has_header('Vary'): 189 189 headerlist = ['HTTP_'+header.upper().replace('-', '_') 190 190 for header in cc_delim_re.split(response['Vary'])] … … 192 192 return _generate_cache_key(request, headerlist, key_prefix) 193 193 else: 194 194 # if there is no Vary header, we still need a cache key 195 # for the request. path195 # for the request.get_full_path() 196 196 cache.set(cache_key, [], cache_timeout) 197 197 return _generate_cache_key(request, [], key_prefix) 198 198 -
django/middleware/cache.py
23 23 24 24 More details about how the caching works: 25 25 26 * Only parameter-lessGET or HEAD-requests with status code 200 are cached.26 * Only GET or HEAD-requests with status code 200 are cached. 27 27 28 28 * The number of seconds each page is stored for is set by the "max-age" section 29 29 of the response's "Cache-Control" header, falling back to the … … 115 115 if self.cache_anonymous_only: 116 116 assert hasattr(request, 'user'), "The Django cache middleware with CACHE_MIDDLEWARE_ANONYMOUS_ONLY=True requires authentication middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.auth.middleware.AuthenticationMiddleware' before the CacheMiddleware." 117 117 118 if not request.method in ('GET', 'HEAD') or request.GET:118 if not request.method in ('GET', 'HEAD'): 119 119 request._cache_update_cache = False 120 120 return None # Don't bother checking the cache. 121 121 -
docs/topics/cache.txt
487 487 said to "vary on language." 488 488 489 489 By default, Django's cache system creates its cache keys using the requested 490 path -- e.g., ``"/stories/2005/jun/23/bank_robbed/"``. This means every request491 to that URL will use the same cached version, regardless of user-agent490 path and query -- e.g., ``"/stories/2005/?order_by=author"``. This means every 491 request to that URL will use the same cached version, regardless of user-agent 492 492 differences such as cookies or language preferences. 493 493 494 494 That's where ``Vary`` comes in.