Data Consistency:
Because NDB is a distributed data storage with eventual consistency, appropriate data modeling is required during data storage. In the same object set, all root entities (without parent) must be unique in ID allocation, and objects with the same parent must not have duplicate IDs, in other words, the relative uniqueness of the ID is determined by the parent. In addition, when using multi_get, it must also be an object with the same parent.
Ancestor and ID-based queries ensure consistency, but the query of the entire object set is not consistent, because the writing of the object is divided into two stages: submission stage and application stage. In the first stage, if the commitlog record is successful, the write operation is successful. If the index is updated in the second stage, no results can be found for non-ancestor or ID queries before the Index Update, And the ancestor and ID queries can return the correct results even if the index is not updated.
Therefore, you must use ancestor to query the answer correctly. In a typical scenario, for example, if multiple answers belong to one question, you can specify the parent of the answer as the question, when a new question is added, You can query all the answers to the question immediately. The new answer is always displayed, and the index is used, for the "latest answer" in chronological order of all answers, you may not be able to see the newly added answer (the index is not updated ).
Cache part:
In the new NDB data storage, Gae provides two-level caches. inprocess 2. the memcache level-1 cache only applies to the current request process. The level-2 cache is automatically cached during query and automatically becomes invalid after the entity owner changes. However, no matter which cache is hit, because it is billed by the number of object queries, there is no impact on billing ~~~
Therefore, it is necessaryProgramTo save money. Parent nodes should also be considered when the object type + id is used as the cache key value to avoid key conflicts.