feat: add endpoint for default caching via redis
Signed-off-by: Ameya Shenoy <shenoy.ameya@gmail.com>
This commit is contained in:
parent
63b2a94440
commit
9629b7b7d2
5 changed files with 33 additions and 8 deletions
|
|
@ -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'),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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/
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ export default new VueRouter({
|
|||
base: process.env.BASE_URL,
|
||||
routes: [
|
||||
{
|
||||
path: '/',
|
||||
path: '/bhavcopy',
|
||||
name: 'bhavcopy',
|
||||
component: BhavCopy,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
</v-card-title>
|
||||
<v-data-table
|
||||
ref="bhavCopyTable"
|
||||
:items="APIData"
|
||||
:items="apiData"
|
||||
:headers="headers"
|
||||
:items-per-page="10"
|
||||
:footer-props="{
|
||||
|
|
@ -75,7 +75,8 @@
|
|||
data() {
|
||||
return {
|
||||
sc_name: '',
|
||||
APIData: [],
|
||||
apiData: [],
|
||||
apiEndpointSelected: 'bhavcopyequity',
|
||||
headersData: [
|
||||
{text: 'Stock Code', value: 'sc_code'},
|
||||
{
|
||||
|
|
@ -101,10 +102,10 @@
|
|||
}
|
||||
},
|
||||
created() {
|
||||
getAPI.get('/bhavcopyequity/',)
|
||||
getAPI.get(`/${this.apiEndpointSelected}/`,)
|
||||
.then(response => {
|
||||
console.log('BhavCopyEquity API has recieved data')
|
||||
this.APIData = response.data
|
||||
this.apiData = response.data
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue