App Engine cache and Data Consistency

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.