Ticket #14103: 14103_with_docs.diff

File 14103_with_docs.diff, 2.5 KB (added by Eric Holscher, 14 years ago)
  • django/utils/cache.py

    diff --git a/django/utils/cache.py b/django/utils/cache.py
    index 6cfd893..5894c76 100644
    a b def patch_response_headers(response, cache_timeout=None):  
    101101        cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS
    102102    if cache_timeout < 0:
    103103        cache_timeout = 0 # Can't have max-age negative
    104     if not response.has_header('ETag'):
     104    if settings.USE_ETAGS and not response.has_header('ETag'):
    105105        response['ETag'] = '"%s"' % md5_constructor(response.content).hexdigest()
    106106    if not response.has_header('Last-Modified'):
    107107        response['Last-Modified'] = http_date()
  • docs/ref/settings.txt

    diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt
    index b5556de..4d70440 100644
    a b USE_ETAGS  
    16401640Default: ``False``
    16411641
    16421642A boolean that specifies whether to output the "Etag" header. This saves
    1643 bandwidth but slows down performance. This is only used if ``CommonMiddleware``
    1644 is installed (see :doc:`/topics/http/middleware`).
     1643bandwidth but slows down performance. This is only in the ``CommonMiddleware`` (see :doc:`/topics/http/middleware`) and in the ``Cache Framework`` (see :doc:`/topics/cache`).
    16451644
    16461645.. setting:: USE_I18N
    16471646
  • tests/regressiontests/cache/tests.py

    diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py
    index 1e0a404..acc8837 100644
    a b class CacheI18nTest(unittest.TestCase):  
    628628        settings.CACHE_MIDDLEWARE_SECONDS = 60
    629629        settings.CACHE_MIDDLEWARE_KEY_PREFIX="test"
    630630        settings.CACHE_BACKEND='locmem:///'
     631        settings.USE_ETAGS = True
    631632        settings.USE_I18N = True
    632633        en_message ="Hello world!"
    633634        es_message ="Hola mundo!"
    class CacheI18nTest(unittest.TestCase):  
    638639        # Check that we can recover the cache
    639640        self.assertNotEqual(get_cache_data.content, None)
    640641        self.assertEqual(en_message, get_cache_data.content)
     642        # Check that we use etags
     643        self.assertTrue(get_cache_data.has_header('ETag'))
     644        # Check that we can disable etags
     645        settings.USE_ETAGS = False
     646        request._cache_update_cache = True
     647        set_cache(request, 'en', en_message)
     648        get_cache_data = FetchFromCacheMiddleware().process_request(request)
     649        self.assertFalse(get_cache_data.has_header('ETag'))
    641650        # change the session language and set content
    642651        request = self._get_request_cache()
    643652        set_cache(request, 'es', es_message)
Back to Top