Add content cache
This commit is contained in:
parent
325fec5271
commit
3a32e32fca
3 changed files with 9 additions and 0 deletions
|
@ -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)
|
||||
|
|
|
@ -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",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue