Search code examples
pythongoogle-app-engineapp-engine-ndb

NDB key vs get_by_id


Just to know if I'm mistaked or not:

get() operations uses NDB cache, so this (Chapter is ndb.Model class):

# Get the entity
chapter_key = ndb.Key('Book', long(bookId), 'Chapter', long(chapterId))
chapter = chapter_key.get()

can use the ndb cache if is 2nd or more read of the entity.

But if I make this?

Chapter.get_by_id(long(id), parent=ndb.Key('Book', long(bookId)))

is this managed by ndb also, or this operation is a standart db operation and don't use cache?


Solution

  • Model.get_by_id will use the context-cache and memcache in exactly the same way as Key.get