1
Fork 0

Add content cache

This commit is contained in:
Jake Howard 2024-04-15 21:12:55 +01:00
parent 325fec5271
commit 3a32e32fca
Signed by: jake
GPG Key ID: 57AFB45680EDD477
3 changed files with 9 additions and 0 deletions

View File

@ -3,6 +3,8 @@ from django.http import HttpResponse
from django.db import connections
from django.shortcuts import get_object_or_404, render
from django.template import Context
from django.views.decorators.cache import cache_page
def search(request):
with connections["default"].cursor() as cursor:
@ -19,3 +21,5 @@ def content(request, slug):
"page": page,
"content": page.content_template.render(Context({"request": request, "page": page}))
})
cached_content = cache_page(600, cache="mem")(content)

View File

@ -90,6 +90,10 @@ CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.filebased.FileBasedCache",
"LOCATION": BASE_DIR / "cache",
},
"mem": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
"LOCATION": "mem",
}
}

View File

@ -21,4 +21,5 @@ urlpatterns = [
path("search/", views.search),
path("content/<slug:slug>/", views.content),
path("__debug__/", include("debug_toolbar.urls")),
path("cached-content/<slug:slug>/", views.cached_content)
]