Sdwebimage Internal implementation Process

Source: Internet
Author: User

1. Entry SetImageWithURL:placeholderImage:options: The Placeholderimage is displayed first, and then the Sdwebimagemanager is processed according to the URL.
2. Enter Sdwebimagemanager-downloadwithurl:delegate:options:userinfo:, give Sdimagecache to find the picture from the cache has been downloaded QueryDiskCacheForKey:delegate:userInfo:.
3. First find out if there is a picture from the memory picture cache, if there is already a picture cache in memory, Sdimagecachedelegate callback ImageCache:didFindImage:forKey:userInfo: To Sdwebimagemanager.
4. Sdwebimagemanagerdelegate callback Webimagemanager:didfinishwithimage: to Uiimageview+webcache and other front-end display pictures.
5. If no memory is in the cache, the build nsinvocationoperation is added to the queue to start looking for pictures from the hard disk if it is already cached.
6. Try to read the picture file according to the Urlkey in the hard disk cache directory. This step is performed at Nsoperation, so the callback notifydelegate is returned to the main thread:.
7. If the previous action reads a picture from the hard disk, the picture is added to the in-memory cache (if the free memory is too small, the memory cache is emptied first). Sdimagecachedelegate callback ImageCache:didFindImage:forKey:userInfo:. And then callback the display image.
8. If the picture is not read from the hard disk cache directory, the picture is not present in all caches, the image needs to be downloaded, callback ImageCache:didNotFindImageForKey:userInfo:.
9. Share or regenerate a downloader sdwebimagedownloader start downloading pictures.
10. Image download by nsurlconnection to do, to achieve the relevant delegate to determine the picture download, download complete and download failed.
Connection:didreceivedata: The use of ImageIO to download the progress by the picture loading effect.
Connectiondidfinishloading: After the data download is finished, give sdwebimagedecoder to do the image decoding processing.
13. Image decoding processing is done in one nsoperationqueue and does not slow down the main thread UI. If there is a need to download the image two times, it is best to complete here, the efficiency will be much better.
14. In the main thread Notifydelegateonmainthreadwithinfo: announce the decoding complete, ImageDecoder:didFinishDecodingImage:userInfo: callback to Sdwebimagedownloader.
Imagedownloader:didfinishwithimage: Callback to Sdwebimagemanager to tell the picture download complete.

16. Notify all downloaddelegates download complete, callback to show the image where needed.
17. Save the picture to Sdimagecache, the memory cache and the hard disk cache are saved simultaneously. Writing files to the hard disk is also done in a separate nsinvocationoperation to avoid slowing down the main thread.
Sdimagecache registers some message notifications at initialization time, cleans up the memory image cache when memory warning or back to the background, and cleans up outdated images when the app is finished.
SDWI also offers uibutton+webcache and mkannotationview+webcache for ease of use.
Sdwebimageprefetcher can pre-download images to facilitate subsequent use.

Sdwebimage Internal implementation Process

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.