From 197f2ea0aab71ef64b25c29a4b922b76fbffa1da Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 2 Oct 2022 18:53:51 +0100 Subject: [PATCH] Move cache handling to views --- website/common/views.py | 5 +++++ website/urls.py | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/website/common/views.py b/website/common/views.py index 1755781..c5f8538 100644 --- a/website/common/views.py +++ b/website/common/views.py @@ -5,6 +5,8 @@ from django.contrib.syndication.views import Feed from django.http.request import HttpRequest from django.http.response import HttpResponse from django.urls import reverse +from django.utils.decorators import method_decorator +from django.views.decorators.cache import cache_control, cache_page from django.views.defaults import ERROR_404_TEMPLATE_NAME from django.views.generic import TemplateView from wagtail.models import Page @@ -33,6 +35,7 @@ class Error404View(TemplateView): page_not_found = Error404View.as_view() +@method_decorator(cache_control(max_age=60 * 60), name="dispatch") class RobotsView(TemplateView): template_name = "robots.txt" content_type = "text/plain" @@ -43,6 +46,7 @@ class RobotsView(TemplateView): return context +@method_decorator(cache_control(max_age=60 * 60), name="dispatch") class KeybaseView(TemplateView): template_name = "keybase.txt" content_type = "text/plain" @@ -52,6 +56,7 @@ class AllPagesFeed(Feed): link = "/feed/" title = "All pages feed" + @method_decorator(cache_page(60 * 60)) def __call__( self, request: HttpRequest, *args: list, **kwargs: dict ) -> HttpResponse: diff --git a/website/urls.py b/website/urls.py index a22777a..c2393b6 100644 --- a/website/urls.py +++ b/website/urls.py @@ -32,12 +32,12 @@ urlpatterns = [ path("sitemap.xml", cache_page(60 * 60)(sitemap), name="sitemap"), path( "robots.txt", - cache_control(max_age=60 * 60)(RobotsView.as_view()), + RobotsView.as_view(), name="robotstxt", ), path( "keybase.txt", - cache_control(max_age=60 * 60)(KeybaseView.as_view()), + KeybaseView.as_view(), name="keybase", ), path("404/", page_not_found, name="404"),