Django

Code

Show
Ignore:
Timestamp:
11/30/07 00:23:24 (1 year ago)
Author:
jkocherhans
Message:

newforms-admin: Merged from trunk up to [6775].

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/newforms-admin

    • Property svnmerge-integrated changed from /django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-6390,6392-6655,6658-6671 to /django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-6390,6392-6776
  • django/branches/newforms-admin/django/middleware/cache.py

    r4824 r6777  
    11from django.conf import settings 
    22from django.core.cache import cache 
    3 from django.utils.cache import get_cache_key, learn_cache_key, patch_response_headers 
     3from django.utils.cache import get_cache_key, learn_cache_key, patch_response_headers, get_max_age 
    44 
    55class CacheMiddleware(object): 
    66    """ 
    77    Cache middleware. If this is enabled, each Django-powered page will be 
    8     cached for CACHE_MIDDLEWARE_SECONDS seconds. Cache is based on URLs
     8    cached (based on URLs)
    99 
    1010    Only parameter-less GET or HEAD-requests with status code 200 are cached. 
     11 
     12    The number of seconds each page is stored for is set by the 
     13    "max-age" section of the response's "Cache-Control" header, falling back to 
     14    the CACHE_MIDDLEWARE_SECONDS setting if the section was not found. 
    1115 
    1216    If CACHE_MIDDLEWARE_ANONYMOUS_ONLY is set to True, only anonymous requests 
     
    7983        if not response.status_code == 200: 
    8084            return response 
    81         patch_response_headers(response, self.cache_timeout) 
    82         cache_key = learn_cache_key(request, response, self.cache_timeout, self.key_prefix) 
    83         cache.set(cache_key, response, self.cache_timeout) 
     85        # Try to get the timeout from the "max-age" section of the "Cache- 
     86        # Control" header before reverting to using the default cache_timeout 
     87        # length. 
     88        timeout = get_max_age(response) 
     89        if timeout == None: 
     90            timeout = self.cache_timeout 
     91        elif timeout == 0: 
     92            # max-age was set to 0, don't bother caching. 
     93            return response 
     94        patch_response_headers(response, timeout) 
     95        cache_key = learn_cache_key(request, response, timeout, self.key_prefix) 
     96        cache.set(cache_key, response, timeout) 
    8497        return response