Implemented redis caching for GET only viewsets

This commit is contained in:
Keannu 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)

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 .models import Semester
from .serializers import SemesterSerializer
@ -6,3 +8,7 @@ from .serializers import SemesterSerializer
class SemesterListView(generics.ListAPIView):
serializer_class = SemesterSerializer
queryset = Semester.objects.all()
@method_decorator(cache_page(60*60))
def dispatch(self, *args, **kwargs):
return super().dispatch(*args, **kwargs)

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, viewsets
from .models import Subject, SubjectInstance
from .serializers import SubjectInstanceSerializer
@ -10,6 +12,10 @@ class SubjectListAllView(generics.ListAPIView):
serializer_class = SubjectInstanceSerializer
queryset = SubjectInstance.objects.all()
@method_decorator(cache_page(60*60))
def dispatch(self, *args, **kwargs):
return super().dispatch(*args, **kwargs)
class SubjectListView(generics.ListAPIView):
permission_classes = [IsAuthenticated]

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 .models import Year_Level
from .serializers import YearLevelSerializer
@ -6,3 +8,7 @@ from .serializers import YearLevelSerializer
class CourseListView(generics.ListAPIView):
serializer_class = YearLevelSerializer
queryset = Year_Level.objects.all()
@method_decorator(cache_page(60*60))
def dispatch(self, *args, **kwargs):
return super().dispatch(*args, **kwargs)