Android Practical Tips-Caching for use

Source: Internet
Author: User

1. Preface

There are several blogs that mention caching, but they are relatively fragmented and recently have a new understanding of the data cache, which has been recorded in my understanding of caching and how I use it in my project.

2. Why data caching is required

Here is my personal opinion.

    • Consider the user experience in extreme environments
      • Off-screen condition
      • Slow speed of the situation
    • Save Client traffic
    • Reduce server pressure
3. What kind of data needs to be cached
    • First, the most need to cache is the picture (this is not much to say)
    • Next is some very important data (such as the app home page data)
4. Common data caching methods and pros and cons
    • File cache
      • The advantage is that you can cache very large data (very small in actual use)
      • Disadvantages of reading and writing cost large
    • Database Cache
      • Advantages data structure is clear and easy to manage
      • Disadvantages same read and write overhead
    • Sharedpreferences
      • Advantages of simple operation, speed is also compared to block
      • The disadvantage only supports basic data types

In the above three methods, I personally like Sharedpreference, in the case of sharedpreference can not meet the requirements, will choose the database cache. Snappy easy to use, fast and worth a try

5. What I know about caching policies
    • Pre-load cache, manual refresh of data (Sina Weibo)
    • Pre-loading the cache while requesting new data and updating the cached data, but not immediately refresh the interface (CSDN client)
    • Pre-load cache, request new data and update the interface inside, cut and update cached data

The above three strategies each have their own advantages and disadvantages, need more practical needs to choose the right strategy.

6. The entire process
    1. Request data
    2. Read cache
    3. Callback Updateview
    4. Continue to request new data
    5. Server returns results
      • The cache data is updated successfully and a more selective method is selected for immediate updating
      • Failed
7. Summary

Data caching is important, data caching is important, and data caching is important. At present, also is to have some understanding to the data cache, also have some practice, take out to share to everybody.

Android Practical Tips-Caching for use

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.