O'Reilly logo

Using Google App Engine by Charles Severance

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building a Session Store Using Memory Cache

We have already used the session object earlier in the book. At that point, we simply downloaded and used the code. Now we will look at the implementation of the session object that we used in Chapter 7 to examine how to use the App Engine memory cache, how to read and set cookies, as well as take a deeper look at how Python supports object-oriented programming.

Although this session object implementation will work for our simple developer applications and would work well for a simple, low-volume App Engine project, it is not a good idea to use this particular implementation for a highly scalable application.

Because our only storage mechanism in this implementation for session data is the memory cache, if our application ran low on memory, our sessions would start disappearing. When a session disappears, our user is unceremoniously logged out from the application. Even worse is that the session system would immediately create a new session and store it in the memory cache, which would further exacerbate the “low memory” problem.

This session implementation would scale to a certain number of users. When too many users use the application at the same time, the application would run low on memory and this session implementation would start failing and thrashing. But our purpose here is to both understand memory cache and sessions, so a nice simple implementation that works 99.9999% of the time suits our purposes at this point.

If you are interested ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required