Just set cache control rather than caching page content
This avoids storing tonnes of stuff in the cache, when it doesn't matter _too_ much
This commit is contained in:
parent
ddb68f7d43
commit
7cd88c9fbd
4 changed files with 19 additions and 11 deletions
|
@ -1,10 +1,10 @@
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
from django.utils.datastructures import OrderedSet
|
||||
from django.views.decorators.cache import cache_page
|
||||
from django.views.decorators.cache import cache_control
|
||||
from pygments.formatters.html import HtmlFormatter
|
||||
|
||||
|
||||
@cache_page(3600)
|
||||
@cache_control(max_age=3600)
|
||||
def pygments_styles(request: HttpRequest) -> HttpResponse:
|
||||
default_styles = (
|
||||
HtmlFormatter(style="default")
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
from django.shortcuts import get_object_or_404
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.decorators.cache import cache_page
|
||||
from django.views.decorators.cache import cache_control
|
||||
from django.views.generic import RedirectView
|
||||
|
||||
from website.blog.models import BlogPostListPage
|
||||
|
||||
|
||||
@method_decorator(cache_page(60 * 60), name="dispatch")
|
||||
@method_decorator(cache_control(max_age=60 * 60), name="dispatch")
|
||||
class PostsFeedView(RedirectView):
|
||||
def get_redirect_url(self) -> str:
|
||||
post_list = get_object_or_404(BlogPostListPage)
|
||||
return post_list.url + post_list.reverse_subpage("feed")
|
||||
|
||||
|
||||
@method_decorator(cache_page(60 * 60), name="dispatch")
|
||||
@method_decorator(cache_control(max_age=60 * 60), name="dispatch")
|
||||
class AllPagesFeedView(RedirectView):
|
||||
pattern_name = "feed"
|
||||
|
|
|
@ -29,8 +29,16 @@ urlpatterns = [
|
|||
name="wagtailimages_serve",
|
||||
),
|
||||
path("sitemap.xml", cache_page(60 * 60)(sitemap), name="sitemap"),
|
||||
path("robots.txt", cache_page(60 * 60)(RobotsView.as_view()), name="robotstxt"),
|
||||
path("keybase.txt", cache_page(60 * 60)(KeybaseView.as_view()), name="keybase"),
|
||||
path(
|
||||
"robots.txt",
|
||||
cache_control(max_age=60 * 60)(RobotsView.as_view()),
|
||||
name="robotstxt",
|
||||
),
|
||||
path(
|
||||
"keybase.txt",
|
||||
cache_control(max_age=60 * 60)(KeybaseView.as_view()),
|
||||
name="keybase",
|
||||
),
|
||||
path("404/", page_not_found, name="404"),
|
||||
path("feed/", AllPagesFeed(), name="feed"),
|
||||
path("", include("website.legacy.urls")),
|
||||
|
|
|
@ -4,7 +4,7 @@ from django.http.request import HttpRequest
|
|||
from django.http.response import HttpResponse
|
||||
from django.utils import timezone
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.decorators.cache import cache_page
|
||||
from django.views.decorators.cache import cache_control
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
from website.contact.models import ContactPage
|
||||
|
@ -17,7 +17,7 @@ class SecurityView(TemplateView):
|
|||
|
||||
expires = timedelta(days=7)
|
||||
|
||||
@method_decorator(cache_page(int(expires.total_seconds() / 2)))
|
||||
@method_decorator(cache_control(max_age=int(expires.total_seconds() / 2)))
|
||||
def dispatch(self, request: HttpRequest) -> HttpResponse:
|
||||
return super().dispatch(request)
|
||||
|
||||
|
@ -36,13 +36,13 @@ class SecurityView(TemplateView):
|
|||
return context
|
||||
|
||||
|
||||
@method_decorator(cache_page(60 * 60), name="dispatch")
|
||||
@method_decorator(cache_control(max_age=60 * 60), name="dispatch")
|
||||
class MatrixServerView(TemplateView):
|
||||
template_name = "well-known/matrix-server.json"
|
||||
content_type = "application/json"
|
||||
|
||||
|
||||
@method_decorator(cache_page(60 * 60), name="dispatch")
|
||||
@method_decorator(cache_control(max_age=60 * 60), name="dispatch")
|
||||
class MatrixClientView(TemplateView):
|
||||
template_name = "well-known/matrix-client.json"
|
||||
content_type = "application/json"
|
||||
|
|
Loading…
Reference in a new issue