summaryrefslogtreecommitdiff
path: root/django/utils/cache.py
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-11-29 20:38:41 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-11-29 20:38:41 +0000
commitdfe05d94b853073e2762250e1b4cd64ce9ef1df0 (patch)
tree4e6aea30920e85556903dd67ca329fe69e9f2a7d /django/utils/cache.py
parentb43a0180322b42925c4c27b5ccdf2e876309c53b (diff)
queryset-refactor: Merged from trunk up to [6752].
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6753 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/cache.py')
-rw-r--r--django/utils/cache.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/django/utils/cache.py b/django/utils/cache.py
index 5654bed7aa..4fcf493944 100644
--- a/django/utils/cache.py
+++ b/django/utils/cache.py
@@ -74,6 +74,21 @@ def patch_cache_control(response, **kwargs):
cc = ', '.join([dictvalue(el) for el in cc.items()])
response['Cache-Control'] = cc
+def get_max_age(response):
+ """
+ Returns the max-age from the response Cache-Control header as an integer
+ (or ``None`` if it wasn't found or wasn't an integer.
+ """
+ if not response.has_header('Cache-Control'):
+ return
+ cc = dict([_to_tuple(el) for el in
+ cc_delim_re.split(response['Cache-Control'])])
+ if 'max-age' in cc:
+ try:
+ return int(cc['max-age'])
+ except (ValueError, TypeError):
+ pass
+
def patch_response_headers(response, cache_timeout=None):
"""
Adds some useful headers to the given HttpResponse object:
@@ -180,3 +195,10 @@ def learn_cache_key(request, response, cache_timeout=None, key_prefix=None):
# for the request.path
cache.set(cache_key, [], cache_timeout)
return _generate_cache_key(request, [], key_prefix)
+
+
+def _to_tuple(s):
+ t = s.split('=',1)
+ if len(t) == 2:
+ return t[0].lower(), t[1]
+ return t[0].lower(), True