diff options
| author | Justin Bronn <jbronn@gmail.com> | 2007-08-26 01:10:53 +0000 |
|---|---|---|
| committer | Justin Bronn <jbronn@gmail.com> | 2007-08-26 01:10:53 +0000 |
| commit | 2052b508eb92c62fc0678efd4936c5ec1e0e735b (patch) | |
| tree | e510109b74b28c8ccef5f6955727cb9dce3da655 /django/utils/cache.py | |
| parent | a7297a255f4bb86f608ea251e00253d18c31d9d4 (diff) | |
gis: Made necessary modifications for unicode, manage refactor, backend refactor and merged 5584-6000 via svnmerge from [repos:django/trunk trunk].
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@6018 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/cache.py')
| -rw-r--r-- | django/utils/cache.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/django/utils/cache.py b/django/utils/cache.py index c8031a409a..2753d86949 100644 --- a/django/utils/cache.py +++ b/django/utils/cache.py @@ -17,9 +17,13 @@ A example: i18n middleware would need to distinguish caches by the "Accept-language" header. """ -import datetime, md5, re +import md5 +import re +import time +from email.Utils import formatdate from django.conf import settings from django.core.cache import cache +from django.utils.encoding import smart_str cc_delim_re = re.compile(r'\s*,\s*') @@ -43,10 +47,10 @@ def patch_cache_control(response, **kwargs): return (t[0].lower().replace('-', '_'), True) def dictvalue(t): - if t[1] == True: + if t[1] is True: return t[0] else: - return t[0] + '=' + str(t[1]) + return t[0] + '=' + smart_str(t[1]) if response.has_header('Cache-Control'): cc = cc_delim_re.split(response['Cache-Control']) @@ -72,16 +76,14 @@ def patch_response_headers(response, cache_timeout=None): """ if cache_timeout is None: cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS - now = datetime.datetime.utcnow() + if cache_timeout < 0: + cache_timeout = 0 # Can't have max-age negative if not response.has_header('ETag'): response['ETag'] = md5.new(response.content).hexdigest() if not response.has_header('Last-Modified'): - response['Last-Modified'] = now.strftime('%a, %d %b %Y %H:%M:%S GMT') + response['Last-Modified'] = formatdate()[:26] + "GMT" if not response.has_header('Expires'): - expires = now + datetime.timedelta(0, cache_timeout) - response['Expires'] = expires.strftime('%a, %d %b %Y %H:%M:%S GMT') - if cache_timeout < 0: - cache_timeout = 0 # Can't have max-age negative + response['Expires'] = formatdate(time.time() + cache_timeout)[:26] + "GMT" patch_cache_control(response, max_age=cache_timeout) def add_never_cache_headers(response): |
