|
@@ -117,12 +117,12 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { |
|
@@ -117,12 +117,12 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { |
117
|
object:nil];
|
117
|
object:nil];
|
118
|
|
118
|
|
119
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
119
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
120
|
- selector:@selector(cleanDisk)
|
120
|
+ selector:@selector(deleteOldFiles)
|
121
|
name:UIApplicationWillTerminateNotification
|
121
|
name:UIApplicationWillTerminateNotification
|
122
|
object:nil];
|
122
|
object:nil];
|
123
|
|
123
|
|
124
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
124
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
125
|
- selector:@selector(backgroundCleanDisk)
|
125
|
+ selector:@selector(backgroundDeleteOldFiles)
|
126
|
name:UIApplicationDidEnterBackgroundNotification
|
126
|
name:UIApplicationDidEnterBackgroundNotification
|
127
|
object:nil];
|
127
|
object:nil];
|
128
|
#endif
|
128
|
#endif
|
|
@@ -441,10 +441,6 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { |
|
@@ -441,10 +441,6 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { |
441
|
[self.memCache removeAllObjects];
|
441
|
[self.memCache removeAllObjects];
|
442
|
}
|
442
|
}
|
443
|
|
443
|
|
444
|
-- (void)clearDisk {
|
|
|
445
|
- [self clearDiskOnCompletion:nil];
|
|
|
446
|
-}
|
|
|
447
|
-
|
|
|
448
|
- (void)clearDiskOnCompletion:(nullable SDWebImageNoParamsBlock)completion {
|
444
|
- (void)clearDiskOnCompletion:(nullable SDWebImageNoParamsBlock)completion {
|
449
|
dispatch_async(self.ioQueue, ^{
|
445
|
dispatch_async(self.ioQueue, ^{
|
450
|
[_fileManager removeItemAtPath:self.diskCachePath error:nil];
|
446
|
[_fileManager removeItemAtPath:self.diskCachePath error:nil];
|
|
@@ -461,11 +457,11 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { |
|
@@ -461,11 +457,11 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { |
461
|
});
|
457
|
});
|
462
|
}
|
458
|
}
|
463
|
|
459
|
|
464
|
-- (void)cleanDisk {
|
|
|
465
|
- [self cleanDiskWithCompletionBlock:nil];
|
460
|
+- (void)deleteOldFiles {
|
|
|
461
|
+ [self deleteOldFilesWithCompletionBlock:nil];
|
466
|
}
|
462
|
}
|
467
|
|
463
|
|
468
|
-- (void)cleanDiskWithCompletionBlock:(nullable SDWebImageNoParamsBlock)completionBlock {
|
464
|
+- (void)deleteOldFilesWithCompletionBlock:(nullable SDWebImageNoParamsBlock)completionBlock {
|
469
|
dispatch_async(self.ioQueue, ^{
|
465
|
dispatch_async(self.ioQueue, ^{
|
470
|
NSURL *diskCacheURL = [NSURL fileURLWithPath:self.diskCachePath isDirectory:YES];
|
466
|
NSURL *diskCacheURL = [NSURL fileURLWithPath:self.diskCachePath isDirectory:YES];
|
471
|
NSArray<NSString *> *resourceKeys = @[NSURLIsDirectoryKey, NSURLContentModificationDateKey, NSURLTotalFileAllocatedSizeKey];
|
467
|
NSArray<NSString *> *resourceKeys = @[NSURLIsDirectoryKey, NSURLContentModificationDateKey, NSURLTotalFileAllocatedSizeKey];
|
|
@@ -544,7 +540,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { |
|
@@ -544,7 +540,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { |
544
|
}
|
540
|
}
|
545
|
|
541
|
|
546
|
#if SD_UIKIT
|
542
|
#if SD_UIKIT
|
547
|
-- (void)backgroundCleanDisk {
|
543
|
+- (void)backgroundDeleteOldFiles {
|
548
|
Class UIApplicationClass = NSClassFromString(@"UIApplication");
|
544
|
Class UIApplicationClass = NSClassFromString(@"UIApplication");
|
549
|
if(!UIApplicationClass || ![UIApplicationClass respondsToSelector:@selector(sharedApplication)]) {
|
545
|
if(!UIApplicationClass || ![UIApplicationClass respondsToSelector:@selector(sharedApplication)]) {
|
550
|
return;
|
546
|
return;
|
|
@@ -558,7 +554,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { |
|
@@ -558,7 +554,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { |
558
|
}];
|
554
|
}];
|
559
|
|
555
|
|
560
|
// Start the long-running task and return immediately.
|
556
|
// Start the long-running task and return immediately.
|
561
|
- [self cleanDiskWithCompletionBlock:^{
|
557
|
+ [self deleteOldFilesWithCompletionBlock:^{
|
562
|
[application endBackgroundTask:bgTask];
|
558
|
[application endBackgroundTask:bgTask];
|
563
|
bgTask = UIBackgroundTaskInvalid;
|
559
|
bgTask = UIBackgroundTaskInvalid;
|
564
|
}];
|
560
|
}];
|