Ticket #20987: cache.py.patch

File cache.py.patch, 1.8 KB (added by shuge.lee@…, 11 years ago)

implement CACHE_MIDDLEWARE_DISABLE_FOR_AUTHENTICATED option for caching

  • middleware/

    old new  
    6666        self.cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS
    6767        self.key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
    6868        self.cache_anonymous_only = getattr(settings, 'CACHE_MIDDLEWARE_ANONYMOUS_ONLY', False)
    69         self.cache_middleware_disable_for_authenticated = getattr(settings, 'CACHE_MIDDLEWARE_DISABLE_FOR_AUTHENTICATED', False)
    7069        self.cache_alias = settings.CACHE_MIDDLEWARE_ALIAS
    7170        self.cache = get_cache(self.cache_alias)
    7271
     
    8786            if request.user.is_authenticated():
    8887                # Don't cache user-variable requests from authenticated users.
    8988                return False
    90         if self.cache_middleware_disable_for_authenticated:
    91             return False
    9289        return True
    9390
    9491    def process_response(self, request, response):
     
    130127        self.cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS
    131128        self.key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
    132129        self.cache_anonymous_only = getattr(settings, 'CACHE_MIDDLEWARE_ANONYMOUS_ONLY', False)
    133         self.cache_middleware_disable_for_authenticated = getattr(settings, 'CACHE_MIDDLEWARE_DISABLE_FOR_AUTHENTICATED', False)
    134130        self.cache_alias = settings.CACHE_MIDDLEWARE_ALIAS
    135131        self.cache = get_cache(self.cache_alias)
    136132
     
    139135        Checks whether the page is already cached and returns the cached
    140136        version if available.
    141137        """
    142         if self.cache_middleware_disable_for_authenticated:
    143             return None
    144 
    145138        if not request.method in ('GET', 'HEAD'):
    146139            request._cache_update_cache = False
    147140            return None # Don't bother checking the cache.
Back to Top