Skip to content

Commit 7b378a7

Browse files
committed
adding cache
1 parent 07fb24a commit 7b378a7

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

azureproject/production.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,15 @@
3838
'PASSWORD': conn_str_params['password'],
3939
}
4040
}
41+
42+
CACHES = {
43+
"default": {
44+
"BACKEND": "django_redis.cache.RedisCache",
45+
"LOCATION": os.environ.get('CACHELOCATION'),
46+
"OPTIONS": {
47+
"CLIENT_CLASS": "django_redis.client.DefaultClient",
48+
"COMPRESSOR": "django_redis.compressors.zlib.ZlibCompressor",
49+
'PASSWORD': os.environ.get('CACHEKEY')
50+
},
51+
}
52+
}

azureproject/settings.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@
119119
},
120120
]
121121

122+
CACHES = {
123+
"default": {
124+
"BACKEND": "django_redis.cache.RedisCache",
125+
"LOCATION": os.environ.get('CACHELOCATION'),
126+
"OPTIONS": {
127+
"CLIENT_CLASS": "django_redis.client.DefaultClient",
128+
'PASSWORD': os.environ.get('CACHEKEY')
129+
},
130+
}
131+
}
122132

123133
# Internationalization
124134
# https://docs.djangoproject.com/en/4.0/topics/i18n/

restaurant_review/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
from django.urls import reverse
55
from django.utils import timezone
66
from django.views.decorators.csrf import csrf_exempt
7+
from django.views.decorators.cache import cache_page
78

89
from restaurant_review.models import Restaurant, Review
910

1011
# Create your views here.
1112

13+
@cache_page(60)
1214
def index(request):
1315
print('Request for index page received')
1416
restaurants = Restaurant.objects.annotate(avg_rating=Avg('review__rating')).annotate(review_count=Count('review'))

0 commit comments

Comments
 (0)