From fd445375ae8eb94e0c642d5d5489023e454a6216 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 20 Aug 2022 18:31:08 +0100 Subject: [PATCH] Add caching to a few simple URLs These do a few queries, and don't change often - ideal for caching --- website/urls.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/website/urls.py b/website/urls.py index 0fb510d..abeb08e 100644 --- a/website/urls.py +++ b/website/urls.py @@ -1,5 +1,6 @@ from django.conf import settings from django.urls import include, path, re_path +from django.views.decorators.cache import cache_page from wagtail import urls as wagtail_urls from wagtail.admin import urls as wagtailadmin_urls from wagtail.contrib.sitemaps.views import sitemap @@ -20,9 +21,13 @@ urlpatterns = [ ServeView.as_view(action="redirect"), name="wagtailimages_serve", ), - path("sitemap.xml", sitemap, name="sitemap"), + path("sitemap.xml", cache_page(60 * 60)(sitemap), name="sitemap"), path("robots.txt", RobotsView.as_view(), name="robotstxt"), - path(".well-known/security.txt", SecurityView.as_view(), name="securitytxt"), + path( + ".well-known/security.txt", + cache_page(SecurityView.expires.total_seconds())(SecurityView.as_view()), + name="securitytxt", + ), path("404/", page_not_found, name="404"), ]