Move cache handling to views
This commit is contained in:
parent
31646007f7
commit
197f2ea0aa
2 changed files with 7 additions and 2 deletions
|
@ -5,6 +5,8 @@ from django.contrib.syndication.views import Feed
|
||||||
from django.http.request import HttpRequest
|
from django.http.request import HttpRequest
|
||||||
from django.http.response import HttpResponse
|
from django.http.response import HttpResponse
|
||||||
from django.urls import reverse
|
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.defaults import ERROR_404_TEMPLATE_NAME
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
from wagtail.models import Page
|
from wagtail.models import Page
|
||||||
|
@ -33,6 +35,7 @@ class Error404View(TemplateView):
|
||||||
page_not_found = Error404View.as_view()
|
page_not_found = Error404View.as_view()
|
||||||
|
|
||||||
|
|
||||||
|
@method_decorator(cache_control(max_age=60 * 60), name="dispatch")
|
||||||
class RobotsView(TemplateView):
|
class RobotsView(TemplateView):
|
||||||
template_name = "robots.txt"
|
template_name = "robots.txt"
|
||||||
content_type = "text/plain"
|
content_type = "text/plain"
|
||||||
|
@ -43,6 +46,7 @@ class RobotsView(TemplateView):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
@method_decorator(cache_control(max_age=60 * 60), name="dispatch")
|
||||||
class KeybaseView(TemplateView):
|
class KeybaseView(TemplateView):
|
||||||
template_name = "keybase.txt"
|
template_name = "keybase.txt"
|
||||||
content_type = "text/plain"
|
content_type = "text/plain"
|
||||||
|
@ -52,6 +56,7 @@ class AllPagesFeed(Feed):
|
||||||
link = "/feed/"
|
link = "/feed/"
|
||||||
title = "All pages feed"
|
title = "All pages feed"
|
||||||
|
|
||||||
|
@method_decorator(cache_page(60 * 60))
|
||||||
def __call__(
|
def __call__(
|
||||||
self, request: HttpRequest, *args: list, **kwargs: dict
|
self, request: HttpRequest, *args: list, **kwargs: dict
|
||||||
) -> HttpResponse:
|
) -> HttpResponse:
|
||||||
|
|
|
@ -32,12 +32,12 @@ urlpatterns = [
|
||||||
path("sitemap.xml", cache_page(60 * 60)(sitemap), name="sitemap"),
|
path("sitemap.xml", cache_page(60 * 60)(sitemap), name="sitemap"),
|
||||||
path(
|
path(
|
||||||
"robots.txt",
|
"robots.txt",
|
||||||
cache_control(max_age=60 * 60)(RobotsView.as_view()),
|
RobotsView.as_view(),
|
||||||
name="robotstxt",
|
name="robotstxt",
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"keybase.txt",
|
"keybase.txt",
|
||||||
cache_control(max_age=60 * 60)(KeybaseView.as_view()),
|
KeybaseView.as_view(),
|
||||||
name="keybase",
|
name="keybase",
|
||||||
),
|
),
|
||||||
path("404/", page_not_found, name="404"),
|
path("404/", page_not_found, name="404"),
|
||||||
|
|
Loading…
Reference in a new issue