Ticket #10387: _generate_cache_header_key.patch

File _generate_cache_header_key.patch, 1.8 KB (added by Travis Swicegood <travis@…>, 16 years ago)
  • django/utils/cache.py

    diff --git django/utils/cache.py django/utils/cache.py
    index 9c566ae..389c5a1 100644
    def _generate_cache_key(request, headerlist, key_prefix):  
    146146    return 'views.decorators.cache.cache_page.%s.%s.%s' % (
    147147               key_prefix, iri_to_uri(request.path), ctx.hexdigest())
    148148
     149def _generate_cache_header_key(key_prefix, request):
     150    """Returns a cache key for the header cache."""
     151    return 'views.decorators.cache.cache_header.%s.%s' % (
     152                    key_prefix, iri_to_uri(request.path))
     153
    149154def get_cache_key(request, key_prefix=None):
    150155    """
    151156    Returns a cache key based on the request path. It can be used in the
    def get_cache_key(request, key_prefix=None):  
    158163    """
    159164    if key_prefix is None:
    160165        key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
    161     cache_key = 'views.decorators.cache.cache_header.%s.%s' % (
    162                     key_prefix, iri_to_uri(request.path))
     166    cache_key = _generate_cache_header_key(key_prefix, request)
    163167    headerlist = cache.get(cache_key, None)
    164168    if headerlist is not None:
    165169        return _generate_cache_key(request, headerlist, key_prefix)
    def learn_cache_key(request, response, cache_timeout=None, key_prefix=None):  
    183187        key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
    184188    if cache_timeout is None:
    185189        cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS
    186     cache_key = 'views.decorators.cache.cache_header.%s.%s' % (
    187                     key_prefix, iri_to_uri(request.path))
     190    cache_key = _generate_cache_header_key(key_prefix, request)
    188191    if response.has_header('Vary'):
    189192        headerlist = ['HTTP_'+header.upper().replace('-', '_')
    190193                      for header in cc_delim_re.split(response['Vary'])]
Back to Top