Sdwebimage mechanism for caching pictures (GO)

Source: Internet
Author: User

Sdwebimageis a very powerful frame for picture caching. After both asihttp+asyncimage, I have been using afnetworking integrated uiimageview+afnetworking.h, but the latter is actually used for the caching of the pictures Nsurlcache comes with the cache mechanism. and Nsurlcache each time to convert the cached raw data into uiimage, resulting in more data processing and memory operations. The specific comparison is here .

Sdwebimage provides the following three category for caching.

    • Mkannotationview (Webcache)
    • UIButton (Webcache)
    • Uiimageview (Webcache)

Take the most commonly used Uiimageview as an example:

  1. uiimageview +webcache:  setimagewithurl:placeholderimage:options:   Displays Placeholderimage first, and Sdwebimagemanager finds pictures locally based on the URL.
  2. sdwebimagemanager :  downloadwithurl:delegate:options:userinfo:  Sdwebimagemanager is the uiimageview+ Webcache linked with Sdimagecache class,  sdimagecache: querydiskcacheforkey:delegate:userinfo: is used to find the picture from the cache based on CacheKey is already in the cache
  3. If there is already a picture cache in memory, Sdwebimagemanager will callback Sdimagecachedelegate:imageCache:didFindImage:forKey:userInfo:
  4. The Uiimageview+webcache callback Sdwebimagemanagerdelegate: webImageManager:didFinishWithImage: to display the picture.
  5. If there is no picture cache in memory, then the build nsinvocationoperation is added to the queue to find whether the picture has been cached from the hard disk.
  6. Try to read the picture file according to Urlkey in the hard disk cache directory. This step is performed at Nsoperation, so the callback is returned to the main thread for the result notifyDelegate: .
  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, and the image needs to be downloaded and recalled imageCache:didNotFindImageForKey:userInfo: .
  9. Share or regenerate a downloader to 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.
  11. connection:didReceiveData:In the use of ImageIO done by the picture download progress loading effect.
  12. connectionDidFinishLoading:After the data download is done, the SDWebImageDecoder image decoding process is done.
  13. The image decoding process is done in a 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. After the main thread notifyDelegateOnMainThreadWithInfo: declares the decoding complete, the imageDecoder:didFinishDecodingImage:userInfo: callback is given to Sdwebimagedownloader.
  15. imageDownloader:didFinishWithImage:Callback to Sdwebimagemanager 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 at the same time.
  18. Write files to the hard disk in a separate nsinvocationoperation to avoid slowing down the main thread.
  19. If you are running on iOS, Sdimagecache will register notification to uiapplicationdidreceivememorywarningnotification when initializing and Uiapplicationwillterminatenotification, in memory warning, clean up the memory image cache, the end of the application to clean up the expired image.
  20. SDWebImagePrefetcherImages can be downloaded in advance to facilitate subsequent use.
Transfer from http://www.overcode.hk/?p=449

Sdwebimage mechanism for caching pictures (GO)

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.