I am trying to understand how ndb uses memcache. From what I gathered so far a request to get() should check if the entity is in memcache already, if it is then retrieve it from memcache and therefore avoid hitting the datastore. If the entity is not in memcache the request is made to the datastore and memcache is updated.
Using Appstats I obtained the following numbers for the case when an entity is in the datastore but it is not yet in memcache:
memcache.Get 2
memcache.Set 2
datastore_v3.Get 1
My expectation for this scenario is:
memcache.Get 1
memcache.Set 1
datastore_v3.Get 1
Here is my code:
import webapp2
from google.appengine.ext import ndb
from models import User
class IndexPage(webapp2.RequestHandler):
def get(self):
user_key = ndb.Key(User, 'user123')
u = user_key.get()
Here is the screenshot from Appstat:

So why is there an extra Get and an extra Set request to memcache?