Add poor-man cache to boards. Fix it later
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.views.decorators.cache import cache_page
|
||||
|
||||
@@ -24,13 +27,19 @@ def board(request, board_slug):
|
||||
"board": board
|
||||
}, status=401)
|
||||
|
||||
cached_page = cache.get(f"board_{board.slug}")
|
||||
if cached_page and board.refreshed_at <= datetime.utcnow() - timedelta(seconds=settings.BOARD_CACHE_SECONDS):
|
||||
return cached_page
|
||||
|
||||
blocks = BoardBlock.objects.filter(board=board)
|
||||
feeds = BoardFeed.objects.filter(board=board)
|
||||
return render(request, "board.html", {
|
||||
result = render(request, "board.html", {
|
||||
"board": board,
|
||||
"blocks": blocks,
|
||||
"feeds": feeds,
|
||||
})
|
||||
cache.set(f"board_{board.slug}", result, settings.BOARD_CACHE_SECONDS)
|
||||
return result
|
||||
|
||||
|
||||
@cache_page(settings.STATIC_PAGE_CACHE_SECONDS)
|
||||
|
||||
@@ -93,6 +93,7 @@ CACHES = {
|
||||
}
|
||||
}
|
||||
STATIC_PAGE_CACHE_SECONDS = 5 * 60 # 5 min
|
||||
BOARD_CACHE_SECONDS = 10 * 60 # 10 min
|
||||
|
||||
# App settings
|
||||
|
||||
|
||||
Reference in New Issue
Block a user