Cache the homepage for anonymous users
authorCharles Connell <charles@connells.org>
Fri, 25 Apr 2014 20:47:23 +0000 (16:47 -0400)
committerCharles Connell <charles@connells.org>
Fri, 25 Apr 2014 20:47:23 +0000 (16:47 -0400)
karmaworld/apps/courses/views.py
karmaworld/settings/prod.py

index ecdb9c78d4332045241d9c550abb954c10ef9001..29445b28022d7e952d7575594bbfb3bb71484d12 100644 (file)
@@ -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)
index c2f16623cc169b555aae49e1ee330c8597ebc275..a6cedce7f5b4fc6640fa9790646fe0afcb5c941c 100644 (file)
@@ -72,6 +72,7 @@ DATABASES = {
 CACHES = {
     'default': {
         'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache',
+        'LOCATION': '127.0.0.1:11211'
     }
 }
 ########## END CACHE CONFIGURATION