Using Memcache

We already know that Memcache is the distributed in-memory data cache provided by App Engine. A typical use case would be to use it as a cache for rapid data retrieval from persistent storage such as Datastore, but we already know that the NDB API does this for us, so there's no need to explicitly cache entities.

Data stored in Memcache can be evicted at any time, so we should cache only data that we can safely lose without affecting integrity. For example, in our Notes application, we can cache the total number of notes globally stored for every user and display this nice kind of metric on the home page. We can perform a Datastore query counting Note entities every time a user visits the main page but this would be cumbersome, possibly ...

Get Python for Google App Engine now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.