Source Address: http://fann.im/blog/2012/08/23/sdwebimage-notes/
Sdwebimage supports asynchronous image download + cache, providing a UIImageView+WebCache category that is easy to use. Record the flow of sdwebimage loading pictures.
- The portal
setImageWithURL:placeholderImage:options: will display the Placeholderimage first, and then Sdwebimagemanager start processing the picture based on the URL.
- Go
downloadWithURL:delegate:options:userInfo: to sdwebimagemanager-and give the SDImageCache search from the cache if the image has been downloaded queryDiskCacheForKey:delegate:userInfo: .
- First from the memory picture cache to find if there is a picture, if there is already a picture cache in memory, Sdimagecachedelegate callback
imageCache:didFindImage:forKey:userInfo: to Sdwebimagemanager.
- Sdwebimagemanagerdelegate callback
webImageManager:didFinishWithImage: to Uiimageview+webcache and other front-end display pictures.
- 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.
- 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: .
- 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.
- 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: .
- Share or regenerate a downloader to
SDWebImageDownloader start downloading pictures.
- Image download by nsurlconnection to do, to achieve the relevant delegate to determine the picture download, download complete and download failed.
connection:didReceiveData:In the use of ImageIO done by the picture download progress loading effect.
connectionDidFinishLoading:After the data download is done, the SDWebImageDecoder image decoding process is done.
- 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.
- After the main thread
notifyDelegateOnMainThreadWithInfo: declares the decoding complete, the imageDecoder:didFinishDecodingImage:userInfo: callback is given to Sdwebimagedownloader.
imageDownloader:didFinishWithImage:Callback to Sdwebimagemanager tell the picture download complete.
- Notify all downloaddelegates download complete, callback to show the image where needed.
- Save the picture to Sdimagecache, the memory cache and the hard disk cache are saved at the same time. 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 the memory is warning or back to the background, and cleans up outdated images when the app is finished.
- Sdwi is also available
UIButton+WebCache and MKAnnotationView+WebCache , for ease of use.
SDWebImagePrefetcherImages can be downloaded in advance to facilitate subsequent use.
IOS 8: "Go" sdwebimage notes