IOS SDWebImage implementation principle explanation, iossdwebimage
Before that, I wrote about how to use SDWebImage, mainly to use and obtain network images. If you have not read it, you can check it out.
This article will mainly introduce the implementation principles of SDWebImage, mainly for obtaining the principles of network images. If there is no third party, how should we do it? Of course, I will introduce the knowledge in text, it is not worthwhile for me to spend a lot of time understanding what we cannot use. However, interested friends can go to other blogs to find relevant information. After all, there is no end to learning. Now let's start with the question.
1) when we need to obtain network images, the first thing we need is that there is no URl in the URl. After obtaining the URL, we implement SDWebImage instead of directly requesting the network, check whether there are URl-related images in the image cache. If yes, the system returns the image directly. If no, the system proceeds to the next step.
2) When there is no image in the image cache, SDWebImage will not be retrieved directly from the network, but will check whether there are images in the sandbox, then, save the corresponding image in the sandbox to the image cache and proceed according to the first step.
3) if the sandbox does not exist, the occupied bitmap is displayed, and the image is cached in the download queue to determine whether the image is being downloaded. If the image is downloaded, the system waits to avoid secondary downloads. If not, a download queue is created. After the download is completed, the download operation is cleared from the queue and the image is saved to the image cache.
4) refresh the UI (depending on the actual situation) and save the image to the sandbox cache.