当前位置:网站首页>Reading sdwebimage source code Notes
Reading sdwebimage source code Notes
2022-07-28 05:06:00 【Lu_ Ca】
- SDWebImage Maximum concurrent number :6.
- Default download timeout :15s.
- Default cache time : a week .
1、SDWebImage Download process 【 These include SDWebImage Cache policy ( Second level cache policy )】
imageView sd_setImageWithUrl:placeholder:options:context:progress{}completed{}
The outermost layer is a SDWebImageManager Single case , Managing two other singletons , One is downloaded SDWebImageDownloader, It manages multiple download operations operation. The other is cache processing SDImageCache. The specific process :
1、 Every time I download pictures , First, according to imageview Of operationDictionary Is there the same key, If there is, it will key Corresponding Operation Cancel and delete .
2、 Add a new task to operation In the dictionary , After loading the picture, it will be based on operation In and out, judge whether it shows , Show and remove if any operation. This is a SD Ways to avoid reuse .
3、 Then it will asynchronously go to the main thread to set the image as placeholder, Set up placehoder Pictures are not cached .
4、 Judge url There is , So called SDWebImageManager Of loadWithUrl: The function passes through SDImageCache From the cache according to CacheKey That is, for downloading url turn MD5 As key To see if the picture is already in the cache .
5、 If the picture is cached in memory , Then call back to Manager, display picture .
6、 If the picture is not in memory , Then it will be generated to find out whether the image exists from the hard disk , If it exists, it will be loaded into memory , If the memory is small, clear the memory first and then save the cache , Callback display picture after reading .
7、 If the picture cannot be read from the hard disk , It means you need to download pictures . then , adopt SDWebImageLoader To download pictures .
9、 Picture download by NSUrlConnection To do it , Monitor the download progress of pictures
10、 stay didFinishLoading Callback method , Process pictures , And turn to the main thread to show the picture
11、 Then save the picture in SDImageCache in , Memory cache and hard disk storage .
2、SDWebImage Image cache cleaning strategy
1、 Get the last modification date of the picture in the disk , Read the attributes of the file, such as the last modification date 、 Size and file path .
2、 Classify the pictures according to the last modification date , Store those files that have exceeded the maximum storage time in the delete array , Other files are saved in another dictionary . Calculate the size after deleting the file to be deleted
3、 Delete the corresponding file according to the file path
4、 Determine whether the remaining file size still exceeds the maximum disk capacity of the user
5、 If it exceeds, the remaining files will be modified and sorted , Delete the file with the earliest modification time , Until the remaining file size is less than maxCacheSize.
3、 Cache cleanup timing
1、 When the system issues a low memory notification , All image caches in memory will be deleted
2、 When the program enters the background , The disk file data will be cleaned
3、 When receiving the program shutdown notice , Clean up the file data on the disk
边栏推荐
- I interviewed a 38 year old programmer and refused to work overtime
- HDU 1435 stable match
- Angr(十一)——官方文档(Part2)
- 数据库故障容错之系统时钟故障
- 数据库日期类型全部为0
- FPGA:使用PWM波控制LED亮度
- Barbie q! How to analyze the new game app?
- Melt cloud x chat, create a "stress free social" habitat with sound
- 在外包公司两年了,感觉快要废了
- Driving the powerful functions of EVM and xcm, how subwallet enables Boca and moonbeam
猜你喜欢

Online sql to XML tool

Improving the readability of UI layer test with puppeter

Professor dongjunyu made a report on the academic activities of "Tongxin sticks to the study of war and epidemic"

(clone virtual machine steps)
![[Hongke technology] Application of network Multimeter in data center](/img/28/2ecc5a7a766454968819c7748fe48e.png)
[Hongke technology] Application of network Multimeter in data center

【ARXIV2204】Simple Baselines for Image Restoration
![(3.1) [Trojan horse synthesis technology]](/img/e7/0e09c1d1bac23022ead7478ea9898a.png)
(3.1) [Trojan horse synthesis technology]

RT_ Use of thread message queue
![[daily question 1] 735. Planetary collision](/img/ba/0ef08ff874f1ddad3fa79b01dba61f.png)
[daily question 1] 735. Planetary collision

flink思维导图
随机推荐
Design and development of C language ATM system project
HDU 3078 network (lca+ sort)
Data imbalance: comprehensive sampling of anti fraud model (data imbalance)
Configuration experiment of building virtual private network based on MPLS
SMD component size metric English system corresponding description
[learning record] data enhancement 1
HashSet add
UI automation test farewell from now on, manual download browser driver, recommended collection
Gym 101911c bacteria (minimum stack)
【ARXIV2203】CMX: Cross-Modal Fusion for RGB-X Semantic Segmentation with Transformers
Method of converting UI file to py file
HDU 1530 maximum clique
Table image extraction based on traditional intersection method and Tesseract OCR
Gan: generative advantageous nets -- paper analysis and the mathematical concepts behind it
How to successfully test php7.1 connecting to sqlserver2008r2
Clickhouse pit filling note 2: the join condition does not support non equal judgments such as greater than and less than
Array or object, date operation
(3.1) [Trojan horse synthesis technology]
Know etcd
FPGA:使用PWM波控制LED亮度