diff options
| author | Ćukasz Langa <lukasz@langa.pl> | 2013-02-25 16:10:57 -0700 |
|---|---|---|
| committer | Carl Meyer <carl@oddbird.net> | 2013-02-25 16:10:57 -0700 |
| commit | 6a057e1595dfe45a0411c116f603801266c87395 (patch) | |
| tree | a57cdf0ae1238949dcb586f34ec50943d3e2bbb1 /django/utils/cache.py | |
| parent | e76147a83a7306d6d83057b982207ddab37eb942 (diff) | |
Fixed #18191 -- Don't consider Accept-Language redundantly in cache key.
Thanks to choongmin for the original patch.
Diffstat (limited to 'django/utils/cache.py')
| -rw-r--r-- | django/utils/cache.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/django/utils/cache.py b/django/utils/cache.py index 0fceaa96e6..8f111592c4 100644 --- a/django/utils/cache.py +++ b/django/utils/cache.py @@ -236,8 +236,18 @@ def learn_cache_key(request, response, cache_timeout=None, key_prefix=None, cach if cache is None: cache = get_cache(settings.CACHE_MIDDLEWARE_ALIAS) if response.has_header('Vary'): - headerlist = ['HTTP_'+header.upper().replace('-', '_') - for header in cc_delim_re.split(response['Vary'])] + is_accept_language_redundant = settings.USE_I18N or settings.USE_L10N + # If i18n or l10n are used, the generated cache key will be suffixed + # with the current locale. Adding the raw value of Accept-Language is + # redundant in that case and would result in storing the same content + # under multiple keys in the cache. See #18191 for details. + headerlist = [] + for header in cc_delim_re.split(response['Vary']): + header = header.upper().replace('-', '_') + if header == 'ACCEPT_LANGUAGE' and is_accept_language_redundant: + continue + headerlist.append('HTTP_' + header) + headerlist.sort() cache.set(cache_key, headerlist, cache_timeout) return _generate_cache_key(request, request.method, headerlist, key_prefix) else: |
