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 nullifying every optimization we made so far. A better strategy would be to keep a counter in the Memcache and increment that counter every time a note is created within the application; if Memcache data expires, we make the counting query...