diff options
| author | Jannis Leidel <jannis@leidel.info> | 2010-02-23 20:45:28 +0000 |
|---|---|---|
| committer | Jannis Leidel <jannis@leidel.info> | 2010-02-23 20:45:28 +0000 |
| commit | 2164e138e32cf8b00a0e43025c64150ec1238cf8 (patch) | |
| tree | b7849ff42df5104e0994a5f2949d8577743f643d /django/utils/cache.py | |
| parent | 6ba5fb37287ab88e2039d754e89788bb864ee123 (diff) | |
Fixed #5691 - Adds the active language to the cache key. Thanks, Antoni Aloy, Ramiro Morales and Yann Malet.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12546 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/cache.py')
| -rw-r--r-- | django/utils/cache.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/django/utils/cache.py b/django/utils/cache.py index 3c40e17e90..9828556057 100644 --- a/django/utils/cache.py +++ b/django/utils/cache.py @@ -19,16 +19,13 @@ An example: i18n middleware would need to distinguish caches by the import re import time -try: - set -except NameError: - from sets import Set as set # Python 2.3 fallback from django.conf import settings from django.core.cache import cache from django.utils.encoding import smart_str, iri_to_uri from django.utils.http import http_date from django.utils.hashcompat import md5_constructor +from django.utils import translation from django.http import HttpRequest cc_delim_re = re.compile(r'\s*,\s*') @@ -145,13 +142,20 @@ def _generate_cache_key(request, headerlist, key_prefix): if value is not None: ctx.update(value) path = md5_constructor(iri_to_uri(request.path)) - return 'views.decorators.cache.cache_page.%s.%s.%s' % ( - key_prefix, path.hexdigest(), ctx.hexdigest()) + cache_key = 'views.decorators.cache.cache_page.%s.%s.%s' % ( + key_prefix, path.hexdigest(), ctx.hexdigest()) + if settings.USE_I18N: + cache_key += '.%s' % translation.get_language() + return cache_key def _generate_cache_header_key(key_prefix, request): """Returns a cache key for the header cache.""" path = md5_constructor(iri_to_uri(request.path)) - return 'views.decorators.cache.cache_header.%s.%s' % (key_prefix, path.hexdigest()) + cache_key = 'views.decorators.cache.cache_header.%s.%s' % ( + key_prefix, path.hexdigest()) + if settings.USE_I18N: + cache_key += ".%s" % translation.get_language() + return cache_key def get_cache_key(request, key_prefix=None): """ |
