1. Miki Tebeka
  2. appengine-py-demo

Commits

Miki Tebeka  committed 9a716d2

Using memcache

  • Participants
  • Parent commits 269c3dc
  • Branches memcache

Comments (0)

Files changed (1)

File shortie.py

View file
  • Ignore whitespace
 from google.appengine.ext import webapp
 from google.appengine.api import users
 from google.appengine.ext import db
+from google.appengine.api import memcache
 import jinja2
 
 from os.path import dirname
     '''Redirect handler, gets short URL and issue an HTTP redirect to the long
     one.'''
     def get(self, short_url):
-        url = get_url(short_url)
-        if not url:
-            log.error('redirect for {0} not found'.format(short_url))
-            self.abort(NOT_FOUND)
+        long_url = memcache.get(short_url)
+        if not long_url:
+            url = get_url(short_url)
+            if not url:
+                log.error('redirect for {0} not found'.format(short_url))
+                self.abort(NOT_FOUND)
+            long_url = str(url.long)
+            memcache.set(short_url, long_url)
 
-        long_url = str(url.long)
         self.redirect(long_url)
 
 app = webapp.WSGIApplication([