分析的版本
pod 'SDWebImage', '~> 5.0.6'
SDWebImage默认清除磁盘缓存的时长是7天。
/** * The maximum length of time to keep an image in the disk cache, in seconds. * Setting this to a negative value means no expiring. * Setting this to zero means that all cached files would be removed when do expiration check. * Defaults to 1 week. */ @property (assign, nonatomic) NSTimeInterval maxDiskAge;
那么SDWebImage是如何进行操作的?
进入SDImageCache的头文件会发现有这么一段代码
- (void)deleteOldFilesWithCompletionBlock:(nullable SDWebImageNoParamsBlock)completionBlock { dispatch_async(self.ioQueue, ^{ [self.diskCache removeExpiredData]; if (completionBlock) { dispatch_async(dispatch_get_main_queue(), ^{ completionBlock(); }); } }); }
调用的地方有两个(APP将要中断,进入后台之后)
- (void)applicationWillTerminate:(NSNotification *)notification
- (void)applicationDidEnterBackground:(NSNotification *)notification