Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.0.X] Fixed #10387: removed some code duplication in django.utils.c…

…ache. Thanks, Travis Swicegood.

Backport of r10223 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10290 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit fd0c4bb76ead305a0717de978a2dc52638f8697b 1 parent 766ff97
@jacobian jacobian authored
Showing with 7 additions and 4 deletions.
  1. +7 −4 django/utils/cache.py
View
11 django/utils/cache.py
@@ -146,6 +146,11 @@ def _generate_cache_key(request, headerlist, key_prefix):
return 'views.decorators.cache.cache_page.%s.%s.%s' % (
key_prefix, iri_to_uri(request.path), ctx.hexdigest())
+def _generate_cache_header_key(key_prefix, request):
+ """Returns a cache key for the header cache."""
+ return 'views.decorators.cache.cache_header.%s.%s' % (
+ key_prefix, iri_to_uri(request.path))
+
def get_cache_key(request, key_prefix=None):
"""
Returns a cache key based on the request path. It can be used in the
@@ -158,8 +163,7 @@ def get_cache_key(request, key_prefix=None):
"""
if key_prefix is None:
key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
- cache_key = 'views.decorators.cache.cache_header.%s.%s' % (
- key_prefix, iri_to_uri(request.path))
+ cache_key = _generate_cache_header_key(key_prefix, request)
headerlist = cache.get(cache_key, None)
if headerlist is not None:
return _generate_cache_key(request, headerlist, key_prefix)
@@ -183,8 +187,7 @@ def learn_cache_key(request, response, cache_timeout=None, key_prefix=None):
key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
if cache_timeout is None:
cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS
- cache_key = 'views.decorators.cache.cache_header.%s.%s' % (
- key_prefix, iri_to_uri(request.path))
+ cache_key = _generate_cache_header_key(key_prefix, request)
if response.has_header('Vary'):
headerlist = ['HTTP_'+header.upper().replace('-', '_')
for header in cc_delim_re.split(response['Vary'])]

0 comments on commit fd0c4bb

Please sign in to comment.
Something went wrong with that request. Please try again.