Authored by Bogdan Poplauschi

Get rid of the confusion cause by `cleanDisk` and `clearDisk`. Renamed `cleanDis…

…k` to `deleteOldFiles`. No longer expose the sync `clearDisk` and `deleteOldFiles`, just the async ones
@@ -191,28 +191,16 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot @@ -191,28 +191,16 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
191 - (void)clearMemory; 191 - (void)clearMemory;
192 192
193 /** 193 /**
194 - * Clear all disk cached images. Non-blocking method - returns immediately.  
195 - * @param completion An block that should be executed after cache expiration completes (optional) 194 + * Async clear all disk cached images. Non-blocking method - returns immediately.
  195 + * @param completion A block that should be executed after cache expiration completes (optional)
196 */ 196 */
197 - (void)clearDiskOnCompletion:(nullable SDWebImageNoParamsBlock)completion; 197 - (void)clearDiskOnCompletion:(nullable SDWebImageNoParamsBlock)completion;
198 198
199 /** 199 /**
200 - * Clear all disk cached images  
201 - * @see clearDiskOnCompletion: 200 + * Async remove all expired cached image from disk. Non-blocking method - returns immediately.
  201 + * @param completionBlock A block that should be executed after cache expiration completes (optional)
202 */ 202 */
203 -- (void)clearDisk;  
204 -  
205 -/**  
206 - * Remove all expired cached image from disk. Non-blocking method - returns immediately.  
207 - * @param completionBlock An block that should be executed after cache expiration completes (optional)  
208 - */  
209 -- (void)cleanDiskWithCompletionBlock:(nullable SDWebImageNoParamsBlock)completionBlock;  
210 -  
211 -/**  
212 - * Remove all expired cached image from disk  
213 - * @see cleanDiskWithCompletionBlock:  
214 - */  
215 -- (void)cleanDisk; 203 +- (void)deleteOldFilesWithCompletionBlock:(nullable SDWebImageNoParamsBlock)completionBlock;
216 204
217 /** 205 /**
218 * Get the size used by the disk cache 206 * Get the size used by the disk cache
@@ -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 }];