iOS programming picture Cache module Design

Source: Internet
Author: User

Why is the mobile client retained? Instead of being blindly replaced by WAP? Because the mobile phone client has the advantage of no alternative to WAP, is its own strong computing power.

The inevitable link in the mobile phone: the picture cache, in the software throughout the operation process is particularly important.

First of all, the role of a cache:

    1. Improve response speed
    2. Reduce network traffic
    3. Improve the user experience

Increased responsiveness: Because once the picture is cached locally, the read of the local IO data is much more efficient than the IO read in the network. So you can improve your response speed.

Reduce network traffic: A picture in some cases, it only loads once, and then does not reload, reducing network traffic. The reduction of traffic is certainly inevitable. The domestic traffic cost is so expensive, it's definitely necessary.

Improve the user experience: This experience is not just about speed, it's also in some disconnected mode. Actually, what I'm trying to say is. Even if our computer hard drive is lost, our software should also be healthy to run, not to mention just broken network.

Of course, this will also bring drawbacks: Data synchronization problems, if the network data to be updated. Then the data you see locally is always old data. In fact, I think this question is a paradox. Reduces network traffic, which is far more than the old data. Of course, special software or certain conditions (WIFI) may require data to be refreshed in a timely manner. Then load the local data first. Then load the data from the network and replace the cached data. This does not conflict with the data cache. At a special point, it's good to have a time period of expiration. For example, downloading a picture is effective within an hour. If it is more than an hour, it is considered invalid. It's slow, but I still see the latest data. As for these strategic issues, we should make the most suitable design according to the different situation, do not repeat here, if you are interested, we can also discuss.

OK, back to the chase. Let's talk about our cache module design. To put it simply, it is to map the network address to a local directory chant. Simply think, the network address of some special fields to replace the OK, such as "/" Replaced by "_" can achieve the purpose of the mapping. or directly in the case of direct transactions to save to local, OK, but this will bring other uncertainties (the length of the network address, if the strategy is not well-developed, will not appear the problem of cache confusion. Issues such as the inability to implement the cache for a short time). My approach is to connect the network address, directly with a local unique cache address to establish a mapping relationship. and is saved to the database, along with the creation time. This allows you to do all of the above caching effects.

Put a thought up first, if you need code. Wait and say.

By the way, there is a detail in the place without saying, how to generate a local unique address? There are several ways to refer to the

    1. Get time as a marker: (not very safe, it may appear in several simultaneous)
    2. Random number: (Not very safe, it is possible to draw the number to the same number)
    3. ID Generator: A component that specialized users generate unique IDs: http://www.cnblogs.com/anxin1225/p/3660506.html

Stick to our official website address: http://www.jinhusns.com

Welcome reprint, but please mark the original address

 

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.