From: Charles Connell Date: Fri, 25 Apr 2014 20:47:23 +0000 (-0400) Subject: Cache the homepage for anonymous users X-Git-Tag: release-20150131~119 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=6c90f0839d56b8b905b0fc0d675de241f2241fa7;p=oweals%2Fkarmaworld.git Cache the homepage for anonymous users --- 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