Anonymous avatar 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})
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.