Incremental update of the mobile side cache

Source: Internet
Author: User

Incremental update of the mobile side cache

In the app, caching is generally introduced for the user experience to speed up the app's operation. And caching this thing with good is the sword, with bad, easy to bring into the dirty data.

In this case, the design idea of incremental update of mobile cache is mentioned. Take the Address book as an example.

Contacts

There are no cache records on the scene 1:app.

There is a cache record on the scene 2:app, but there is a time when the app is not being used, and you cannot ensure that the cache is up to date.

Scenario 3:app is using the cache.

Of the three scenarios above, Scenario 2 is the most troubling, as the server may have crud the information in the Address Book for a time period that the app does not use .

Here we step-by-step analysis of Scenario 2 solutions.

UpdateTime and isDeleted

To cope with scenario 2, an incremental update is often used, where each piece of data is added with the Update_time field to confirm what data is generated when the app is not in use. So that when the app is used again, the app sends the last update timestamp to the server, and the server can return the correct update package to the app. Step through the crud:

1. For C (new): If the server adds a piece of data to the Address book in the database, the update_time of that data is the current time of the server. This way, when the app is syncing, the server knows what data is generated without using the app's time period.

2. For R (Read): no effect

3. For u (UPDATE): When the server modifies the Address book entry, the Update_time is also modified to the current time of the server. This way, when the app is syncing, the server knows what data is being updated without using the app's time period.

4. For d (delete): If the server deletes (hard delete) the entries in the Address book, the app will not be able to determine what data is deleted without using the app time period, and if it is processed according to Update_time comparison, the app has dirty data ( The data that should be deleted is not deleted). to solve this problem , you need to add a flag, isdeleted, to indicate whether the data was deleted. This way, when the server deletes the data, the isdeleted=true can be updated, and the data is update_time to the server time . So when the app syncs, you know what data is deleted when you're not using the app .

  To this, it is better to solve the problem of scene 2, and Scene 1 and Scene 3, can be considered as a special case of Scene 2.

  The basic principle of an incremental update is to add a update_time representation, because time is ordered, so you can find data that changes from a fixed point. If the data is deleted, in order to avoid the cache not deleting the deleted data in the server, the soft-deletion method is adopted.

Incremental update of the mobile side cache

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.