2008-09-17

The memcache API in GAE is neat

With my web site being my first real web site in several years (last one used PHP to generate static HTML and I devised my own way of not hard-coding URLs), I finally learning about some stuff that I am sure people have been using for a while, such as memcached.

Google App Engine provides an API that is apparently similar to the one provided by memcached. They have aptly enough named the module memcache. I decided to use it where I could so as to learn about it (my web site doesn't get enough traffic to really warrant bothering with memcache).

Once I realized the best way to use the memcache is to factor out the part of a view that generates consistent content (e.g. what objects to view, but not necessarily an entire page if it has dynamic stuff that really needs to be generated every time accurately), I threw together a memcache decorator that handles checking the memcache and either returning what is there or calling the content creating function and then setting what it returns in the memcache. I also set the time to 1 second if I am debugging so as to not constantly hit the memcache when I am making changes quickly to the code.