Miki Tebeka avatar Miki Tebeka committed 9a716d2

Using memcache

Comments (0)

Files changed (1)

 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([
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.