From 6c90f0839d56b8b905b0fc0d675de241f2241fa7 Mon Sep 17 00:00:00 2001 From: Charles Connell Date: Fri, 25 Apr 2014 16:47:23 -0400 Subject: [PATCH] Cache the homepage for anonymous users --- karmaworld/apps/courses/views.py | 7 ++++++- karmaworld/settings/prod.py | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/karmaworld/apps/courses/views.py b/karmaworld/apps/courses/views.py index ecdb9c7..29445b2 100644 --- a/karmaworld/apps/courses/views.py +++ b/karmaworld/apps/courses/views.py @@ -10,6 +10,7 @@ from django.core.exceptions import MultipleObjectsReturned from django.core.exceptions import ObjectDoesNotExist from django.http import HttpResponse, HttpResponseBadRequest +from django.views.decorators.cache import cache_page from django.views.generic import View from django.views.generic import DetailView from django.views.generic import TemplateView @@ -36,7 +37,11 @@ class CourseListView(View): """ def get(self, request, *args, **kwargs): - return CourseListSubView.as_view()(request, *args, **kwargs) + if request.user.is_authenticated(): + return CourseListSubView.as_view()(request, *args, **kwargs) + # Cache the homepage for non-authenicated users + else: + return cache_page(CourseListSubView.as_view(), 60 * 60)(request, *args, **kwargs) def post(self, request, *args, **kwargs): ret = CourseAddFormView.as_view()(request, *args, **kwargs) diff --git a/karmaworld/settings/prod.py b/karmaworld/settings/prod.py index c2f1662..a6cedce 100644 --- a/karmaworld/settings/prod.py +++ b/karmaworld/settings/prod.py @@ -72,6 +72,7 @@ DATABASES = { CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache', + 'LOCATION': '127.0.0.1:11211' } } ########## END CACHE CONFIGURATION -- 2.25.1