Commits

Anonymous committed edcaca1

fix caching

Comments (0)

Files changed (1)

gaepuv/puv/poll/views.py

 from puv.settings import *
 from puv.poll.utils import getGeoIPCode, mail_poll
 from datetime import datetime
-from google.appengine.api import memcache
+# from google.appengine.api import memcache
+from django.views.decorators.cache import cache_page
 
 APP_ID = os.environ['APPLICATION_ID'] 
 VERSION = os.environ.get('CURRENT_VERSION_ID','0') 
          draggable: false
        });
        '''
-def get_home(time=3600):
-    """ Checks the cache to for home page or sets it - time = hour by default """
-    home = memcache.get("home")
-    if home is not None:
-        return home
-    else:
-        polls = models.Poll.all().order('-created_on').filter('private =', False).fetch(20)
-        home = render_to_response('index.html', {'polls':polls})
-        if not memcache.add("home", home, time):
-            logging.error("Memcache set failed.")
-        return home
+
+@cache_page(600)
+def get_home(request):
+    """ Checks the cache to for home page or sets it - time = 10 mins by default """
+    polls = models.Poll.all().order('-created_on').filter('private =', False).fetch(20)
+    return render_to_response('index.html', {'polls':polls})
 
 def feed(request, template='atom.xml', user=None):
     """ Get atom or rss feed of polls - latest or for user 
 def index(request, template='index.html'):
     """ Used for listing polls on the home page, vote index and results index pages """
     if template == 'index.html':
-        return get_home()
+        return get_home(request)
     else:
         polls = models.Poll.all().order('-created_on').filter('private =', False).fetch(20)
         return render_to_response(template, {'polls':polls})