Disable global cache, make it per view

This commit is contained in:
Vasily Zubarev
2020-01-13 11:03:12 +01:00
parent 95a151d2c2
commit d6f002a284
2 changed files with 7 additions and 3 deletions

View File

@@ -1,9 +1,12 @@
from django.conf import settings
from django.shortcuts import render, get_object_or_404
from django.views.decorators.cache import cache_page
from auth.helpers import authorized_user
from boards.models import Board, BoardBlock, BoardFeed
@cache_page(settings.STATIC_PAGE_CACHE_SECONDS)
def index(request):
boards = Board.objects.filter(is_visible=True).all()
return render(request, "index.html", {
@@ -30,9 +33,12 @@ def board(request, board_slug):
})
@cache_page(settings.STATIC_PAGE_CACHE_SECONDS)
def what(request):
return render(request, "what.html")
@cache_page(settings.STATIC_PAGE_CACHE_SECONDS)
def privacy_policy(request):
return render(request, "docs/privacy_policy.html")

View File

@@ -20,9 +20,7 @@ INSTALLED_APPS = [
]
MIDDLEWARE = [
"django.middleware.cache.UpdateCacheMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.cache.FetchFromCacheMiddleware"
]
ROOT_URLCONF = "infomate.urls"
@@ -94,7 +92,7 @@ CACHES = {
"LOCATION": os.path.join(BASE_DIR, "../django_cache.tmp")
}
}
CACHE_MIDDLEWARE_SECONDS = 60
STATIC_PAGE_CACHE_SECONDS = 5 * 60 # 5 min
# App settings