From 66fdc16524b21e3fc2edb80894e390569e254554 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Tue, 12 Sep 2023 19:51:06 +0800 Subject: [PATCH] Implemented redis caching for GET only viewsets --- stude/landmarks/views.py | 6 ++++++ stude/semesters/views.py | 6 ++++++ stude/subjects/views.py | 6 ++++++ stude/year_levels/views.py | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/stude/landmarks/views.py b/stude/landmarks/views.py index 9a064f5..32d3647 100644 --- a/stude/landmarks/views.py +++ b/stude/landmarks/views.py @@ -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) diff --git a/stude/semesters/views.py b/stude/semesters/views.py index d7ab49c..0a25ed2 100644 --- a/stude/semesters/views.py +++ b/stude/semesters/views.py @@ -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) diff --git a/stude/subjects/views.py b/stude/subjects/views.py index 170a490..1887386 100644 --- a/stude/subjects/views.py +++ b/stude/subjects/views.py @@ -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] diff --git a/stude/year_levels/views.py b/stude/year_levels/views.py index c7b8358..509a79f 100644 --- a/stude/year_levels/views.py +++ b/stude/year_levels/views.py @@ -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)