diff --git a/wagtail/wagtailadmin/tests/tests.py b/wagtail/wagtailadmin/tests/tests.py index 9c8dc95df9..07fea53e7c 100644 --- a/wagtail/wagtailadmin/tests/tests.py +++ b/wagtail/wagtailadmin/tests/tests.py @@ -28,6 +28,14 @@ class TestHome(TestCase, WagtailTestUtils): response = self.client.get(reverse('wagtailadmin_home') + '?hide-kittens=true') self.assertNotContains(response, 'Kittens!') + def test_never_cache_header(self): + # This tests that wagtailadmins global cache settings have been applied correctly + response = self.client.get(reverse('wagtailadmin_home')) + + self.assertIn('private', response['Cache-Control']) + self.assertIn('no-cache', response['Cache-Control']) + self.assertIn('no-store', response['Cache-Control']) + class TestEditorHooks(TestCase, WagtailTestUtils): def setUp(self): diff --git a/wagtail/wagtailadmin/urls.py b/wagtail/wagtailadmin/urls.py index e2890cf33f..efcf1bc70f 100644 --- a/wagtail/wagtailadmin/urls.py +++ b/wagtail/wagtailadmin/urls.py @@ -1,5 +1,6 @@ from django.conf.urls import url from django.contrib.auth.decorators import permission_required +from django.views.decorators.cache import cache_control from wagtail.wagtailadmin.forms import PasswordResetForm from wagtail.wagtailadmin.views import account, chooser, home, pages, tags, userbar, page_privacy @@ -117,3 +118,8 @@ urlpatterns += [ }, name='wagtailadmin_password_reset_complete' ), ] + +# Decorate all views with cache settings to prevent caching +urlpatterns = decorate_urlpatterns(urlpatterns, + cache_control(private=True, no_cache=True, no_store=True) +)