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