Cache template snipped for shelve buttons

This commit is contained in:
Mouse Reeve
2022-01-04 17:59:35 -08:00
parent 1bd813c6f7
commit 5981575f0e
2 changed files with 9 additions and 0 deletions

View File

@ -1,5 +1,7 @@
""" the good stuff! the books! """
from django.contrib.auth.decorators import login_required
from django.core.cache import cache
from django.core.cache.utils import make_template_fragment_key
from django.db import transaction
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseNotFound
from django.shortcuts import get_object_or_404, redirect
@ -44,6 +46,10 @@ class ReadingStatus(View):
if not identifier:
return HttpResponseBadRequest()
# invalidate the template cache
cache_key = make_template_fragment_key("shelve_button", [request.user.id, book_id])
cache.delete(cache_key)
desired_shelf = get_object_or_404(
models.Shelf, identifier=identifier, user=request.user
)