Android Practical Skills-Analysis of Cache Usage

Source: Internet
Author: User

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.

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.