Implemented redis caching for GET only viewsets

This commit is contained in:
Keannu Christian Bernasol 2023-09-12 19:51:06 +08:00
parent 0215680ea5
commit 66fdc16524
4 changed files with 24 additions and 0 deletions

View file

@ -1,3 +1,5 @@
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from rest_framework import generics
from rest_framework.permissions import IsAuthenticated
from .serializers import LandmarkSerializer
@ -8,3 +10,7 @@ class LandmarkListView(generics.ListAPIView):
serializer_class = LandmarkSerializer
# permission_classes = [IsAuthenticated]
queryset = Landmark.objects.all()
@method_decorator(cache_page(60*60))
def dispatch(self, *args, **kwargs):
return super().dispatch(*args, **kwargs)