Browse files

Fixed #2541 -- Added helpful error message for CacheMiddleware in the…

… case of CACHE_ANONYMOUS_ONLY=True and uninstalled/unordered AuthenticationMiddleware. Thanks,

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 8f065bb commit d592ca487ae4be5b7fdc22e6022bb766eeafab39 @adrianholovaty adrianholovaty committed Aug 18, 2006
Showing with 3 additions and 0 deletions.
  1. +3 −0 django/middleware/
3 django/middleware/
@@ -41,6 +41,9 @@ def __init__(self, cache_timeout=None, key_prefix=None, cache_anonymous_only=Non
def process_request(self, request):
"Checks whether the page is already cached and returns the cached version if available."
+ if self.cache_anonymous_only:
+ 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."
if not request.method in ('GET', 'HEAD') or request.GET:
request._cache_update_cache = False
return None # Don't bother checking the cache.

0 comments on commit d592ca4

Please sign in to comment.