Android Practical Skills-Analysis of Cache Usage
1. Preface
I have mentioned caching in previous blogs, but it is scattered. Recently I have gained a new understanding of data caching, so I will record my understanding of caching, and how I use it in projects.
2. Why data caching?
My personal opinion is as follows.
Consider the user experience in extreme environments
If the network is disconnected, the network speed is slow, saving Client Traffic and reducing server pressure 3. what kind of data needs to be cached first is the image (not to mention), followed by some very important data (such as app homepage data) 4. common data caching methods and advantages and disadvantages file caching
Advantage: large data can be cached (very small in actual use) Disadvantage: read/write overhead large database cache
Advantages: clear data structure, easy to manage disadvantages, as well as high read/write overhead sharedpreferences
Advantage: simple operation and low speed. disadvantage: only basic data types are supported.
Among the above three methods, I personally like sharedpreference. If sharedpreference cannot meet the requirements, the database cache will be selected. Snappy is easy to use and fast, so it is worth a try.
5. the cache policies I know pre-load the cache. You need to manually refresh the cache to pre-load the data (Sina Weibo), and request new data and update the cache data, but instead of immediately refreshing the interface (csdn client) to pre-load the cache, request new data and update the interface, and switch to and update the cache data.
The above three policies have their own advantages and disadvantages, and you need to select the appropriate policy as needed.
6. Throughout the process, the request data read cache callback updateview continues to request the results returned by the new data server
Cache data is updated successfully. Select whether to update immediately or not. 7. Summary
Data caching is important, data caching is important, and data caching is important. At present, I have some understanding about data caching and some practices. I will share them with you.