Client-Side Caching mechanisms

Source: Internet
Author: User

I. INTRODUCTIONThe client-side caching mechanism not only reduces the pressure on the server, but also allows the user to get a good user experience in the case of slow speed. So building a good app, caching is an important part of it.

Two. The processing solution client obtains the latest data from the server, if it is 20, and caches the data locally, and when the next page of data is loaded, the data is not only added to memory, but also synchronized to the cache. In this way, the in-memory data remains consistent with the cached data.
When the user restarts the refresh interface, there are two cases when the user data change is less than one page, and the second is that the user data change is greater than one page.
The first case is relatively simple, the data change is less than one page, indicating that the refreshed returned data plus the cached data can be built out of the user's entire data, so at this time only need to merge refresh the return of the latest data and cached data, the duplicate data can be removed.
The second situation is more complex, the data changes more than one page, indicating that the refresh of the return data and cached data between the missing part of the data, how to synchronize this part of the data? The simple scenario is that if this happens, then the cache is refactored, and the refactoring cache means removing the old cache information and re-adding the cache. The advantage of this scheme is that the implementation is simple and error-prone, but the disadvantage is that if frequent refactoring caches lose the meaning of caching. The real solution to the problem of intermediate data acquisition, you can create a temporary array, the current in-memory data into a temporary variable, and then the refresh returned data into memory, when the user triggered the loading of more events, to determine whether the latest returned data is coincident with the data in the temporary variable, There is a coincidence that the missing data in the middle is finished, then the data of the temporary variable is merged into memory. Of course, in-memory operations need to be synchronized to the cache.
Each time the user re-enters the module, it loads the data into memory from the cache and then automatically merges the latest data with the in-memory data. Display the cached data directly if the user network is not in line.


Exception Handling: Network exception--Display cache data memory overflow--Limit number of cache bars

Three. The following issues are encountered in the above scenario:
    1. When loading more, the page and size of the paging page, when the user data frequently updated, there will be redundant data, such as the last two of the first page may be the top two of the second page.
    2. Synchronization problem, in some businesses, the data is mostly constant, but some of the data will change, such as Weibo, Weibo content will not change, but the number of forwarding lines, the number of comments is changing. If only the data in the cache will appear and the server side is out of sync
    3. Cache does not have a cleanup function, and as time grows, there is always a memory overflow situation
Resolution: Issue 1: Get Data Time Division page added Sinceid and Maxid, to control the maximum and minimum data ID, so as to prevent redundant duplicate data problem 2: For frequent small chunks (such as reading, share number) can develop synchronization protocol, Update these small chunks without updating the overall data problem 3: Memory growth can be controlled by limiting the number of cache bars, and when the number of cache bars exceeds the limit, the cache is reconstructed for the user (updates to large chunks can also be implemented by timed refactoring caches)

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Client-Side Caching mechanisms

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.