Ticket #5691: django_utils_cache_patch.diff

File django_utils_cache_patch.diff, 2.4 KB (added by aaloy <aaloy@…>, 17 years ago)

a patch with the proposed cache key

  • django/utils/cache.py

     
    2424from django.conf import settings
    2525from django.core.cache import cache
    2626from django.utils.encoding import smart_str, iri_to_uri
     27from django.utils import translation
    2728
    2829cc_delim_re = re.compile(r'\s*,\s*')
    2930
     
    121122def _generate_cache_key(request, headerlist, key_prefix):
    122123    "Returns a cache key from the headers given in the header list."
    123124    ctx = md5.new()
     125    lang = translation.get_language()
    124126    for header in headerlist:
    125127        value = request.META.get(header, None)
    126128        if value is not None:
    127129            ctx.update(value)
    128     return 'views.decorators.cache.cache_page.%s.%s.%s' % (key_prefix, iri_to_uri(request.path), ctx.hexdigest())
     130    return 'views.decorators.cache.cache_page.%s.%s.%s_%s' % (key_prefix, iri_to_uri(request.path), ctx.hexdigest(),lang)
    129131
    130132def get_cache_key(request, key_prefix=None):
    131133    """
     
    137139    If there is no headerlist stored, the page needs to be rebuilt, so this
    138140    function returns None.
    139141    """
     142    lang = translation.get_language()
    140143    if key_prefix is None:
    141144        key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
    142     cache_key = 'views.decorators.cache.cache_header.%s.%s' % (key_prefix, iri_to_uri(request.path))
     145    cache_key = 'views.decorators.cache.cache_header.%s.%s_%s' % (key_prefix, iri_to_uri(request.path),lang)
    143146    headerlist = cache.get(cache_key, None)
    144147    if headerlist is not None:
    145148        return _generate_cache_key(request, headerlist, key_prefix)
     
    159162    cache, this just means that we have to build the response once to get at
    160163    the Vary header and so at the list of headers to use for the cache key.
    161164    """
     165    lang = translation.get_language()
    162166    if key_prefix is None:
    163167        key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
    164168    if cache_timeout is None:
    165169        cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS
    166     cache_key = 'views.decorators.cache.cache_header.%s.%s' % (key_prefix, iri_to_uri(request.path))
     170    cache_key = 'views.decorators.cache.cache_header.%s.%s_%s' % (key_prefix, iri_to_uri(request.path),lang)
    167171    if response.has_header('Vary'):
    168172        headerlist = ['HTTP_'+header.upper().replace('-', '_') for header in vary_delim_re.split(response['Vary'])]
    169173        cache.set(cache_key, headerlist, cache_timeout)
Back to Top