Ticket #5047: patch_cache_controll.diff
File patch_cache_controll.diff, 1.5 KB (added by , 17 years ago) |
---|
-
django/utils/cache.py
27 27 28 28 cc_delim_re = re.compile(r'\s*,\s*') 29 29 30 def patch_cache_control(response, **kwargs):30 def patch_cache_control(response, rewrite = True, **kwargs): 31 31 """ 32 32 This function patches the Cache-Control header by adding all 33 33 keyword arguments to it. The transformation is as follows: 34 34 35 * If rewrite set to False, then value 'max-age' in current Cache-Control 36 header remains untouched, otherwise it could be rewritten by value from 37 kwargs 35 38 * All keyword parameter names are turned to lowercase, and underscores 36 39 are converted to hyphens. 37 40 * If the value of a parameter is True (exactly True, not just a … … 57 60 cc = dict([dictitem(el) for el in cc]) 58 61 else: 59 62 cc = {} 63 64 if not rewrite and 'max-age' in cc and 'max_age' in kwargs: 65 del kwargs['max_age'] 66 60 67 for (k,v) in kwargs.items(): 61 68 cc[k.replace('_', '-')] = v 62 69 cc = ', '.join([dictvalue(el) for el in cc.items()]) … … 84 91 response['Last-Modified'] = formatdate()[:26] + "GMT" 85 92 if not response.has_header('Expires'): 86 93 response['Expires'] = formatdate(time.time() + cache_timeout)[:26] + "GMT" 87 patch_cache_control(response, max_age=cache_timeout)94 patch_cache_control(response, rewrite = False, max_age=cache_timeout) 88 95 89 96 def add_never_cache_headers(response): 90 97 """