diff --git a/backend/app/urls.py b/backend/app/urls.py index 438465d..b5e5178 100644 --- a/backend/app/urls.py +++ b/backend/app/urls.py @@ -1,6 +1,7 @@ from django.urls import path -from app.views import BhavCopyEquityView +from app.views import BhavCopyEquityView, BhavCopyEquityDefaultRedisView urlpatterns = [ path('bhavcopyequity/', BhavCopyEquityView.as_view(), name='bhavcopyequity_view'), + path('bhavcopyequitydefaultredis/', BhavCopyEquityDefaultRedisView.as_view(), name='bhavcopyequity_view'), ] diff --git a/backend/app/views.py b/backend/app/views.py index 9635707..130b6d4 100644 --- a/backend/app/views.py +++ b/backend/app/views.py @@ -1,9 +1,16 @@ + +# third-party imports from rest_framework.response import Response from rest_framework import generics +from django.utils.decorators import method_decorator +from django.views.decorators.cache import cache_page + +# app imports from app.models import BhavCopyEquity from app.serializers import BhavCopyEquitySerializer + # Create your views here. class BhavCopyEquityView(generics.RetrieveAPIView): queryset = BhavCopyEquity.objects.all() @@ -11,5 +18,18 @@ class BhavCopyEquityView(generics.RetrieveAPIView): def get(self, request, *args, **kwargs): queryset = self.get_queryset() serializer = BhavCopyEquitySerializer(queryset, many=True) + print("without redis") return Response(serializer.data) + +class BhavCopyEquityDefaultRedisView(generics.RetrieveAPIView): + queryset = BhavCopyEquity.objects.all() + + @method_decorator(cache_page(60*60*2)) + def get(self, request, *args, **kwargs): + queryset = self.get_queryset() + serializer = BhavCopyEquitySerializer(queryset, many=True) + print("without redis") + return Response(serializer.data) + + diff --git a/backend/backend/settings.py b/backend/backend/settings.py index 5f86446..e79e194 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -97,8 +97,8 @@ DATABASES = { CACHES = { 'default': { - 'BACKEND': 'redis_cache.cache.RedisCache', - 'LOCATION': 'redis:6379/1', + 'BACKEND': 'django_redis.cache.RedisCache', + 'LOCATION': 'redis://redis:6379/1', 'OPTIONS': { 'CLIENT_CLASS': 'django_redis.client.DefaultClient', }, @@ -152,6 +152,9 @@ RQ_QUEUES = { }, } +SESSION_ENGINE = "django.contrib.sessions.backends.cache" +SESSION_CACHE_ALIAS = "default" +CACHE_TTL = 60 * 5 # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.1/howto/static-files/ diff --git a/frontend/src/routes.js b/frontend/src/routes.js index 9bc0480..0da1fa2 100644 --- a/frontend/src/routes.js +++ b/frontend/src/routes.js @@ -10,7 +10,7 @@ export default new VueRouter({ base: process.env.BASE_URL, routes: [ { - path: '/', + path: '/bhavcopy', name: 'bhavcopy', component: BhavCopy, } diff --git a/frontend/src/views/BhavCopy.vue b/frontend/src/views/BhavCopy.vue index aff960b..f6755cd 100644 --- a/frontend/src/views/BhavCopy.vue +++ b/frontend/src/views/BhavCopy.vue @@ -25,7 +25,7 @@