Ticket #1509: anonymous_caching.patch
File anonymous_caching.patch, 2.2 KB (added by , 19 years ago) |
---|
-
Users/mcroydon/django/django_src.trunk/django/middleware/cache.py
9 9 cached for CACHE_MIDDLEWARE_SECONDS seconds. Cache is based on URLs. 10 10 11 11 Only parameter-less GET or HEAD-requests with status code 200 are cached. 12 13 If CACHE_MIDDLEWARE_ANONYMOUS_ONLY is set to True, only anonymous requests 14 (those not made by a logged in user) are cached. 12 15 13 16 This middleware expects that a HEAD request is answered with a response 14 17 exactly like the corresponding GET request. … … 23 26 This middleware also sets ETag, Last-Modified, Expires and Cache-Control 24 27 headers on the response object. 25 28 """ 26 def __init__(self, cache_timeout=None, key_prefix=None ):29 def __init__(self, cache_timeout=None, key_prefix=None, cache_anonymous=None): 27 30 self.cache_timeout = cache_timeout 28 31 if cache_timeout is None: 29 32 self.cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS 30 33 self.key_prefix = key_prefix 31 34 if key_prefix is None: 32 35 self.key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX 36 self.cache_anonymous = cache_anonymous 37 if cache_anonymous is None and hasattr(settings, "CACHE_MIDDLEWARE_ANONYMOUS_ONLY"): 38 self.cache_anonymous = settings.CACHE_MIDDLEWARE_ANONYMOUS_ONLY 33 39 34 40 def process_request(self, request): 35 "Checks whether the page is already cached and returns the cached version if available." 41 "Checks whether the page is already cached and returns the cached version if available." 36 42 if not request.META['REQUEST_METHOD'] in ('GET', 'HEAD') or request.GET: 37 43 request._cache_update_cache = False 38 44 return None # Don't bother checking the cache. 45 46 if self.cache_anonymous and not request.user.is_anonymous(): 47 request._cache_update_cache = False 48 return None # Don't cache logged in users 39 49 40 50 cache_key = get_cache_key(request, self.key_prefix) 41 51 if cache_key is None: