diff --git a/SDWebImage/SDImageCache.h b/SDWebImage/SDImageCache.h index 0eab5d61..84812ed0 100644 --- a/SDWebImage/SDImageCache.h +++ b/SDWebImage/SDImageCache.h @@ -142,6 +142,7 @@ typedef NS_ENUM(NSInteger, SDImageCacheType) { * Clear all disk cached images */ - (void)clearDisk; +- (void)clearDiskOnCompletion:(void (^)())completion; /** * Remove all expired cached image from disk diff --git a/SDWebImage/SDImageCache.m b/SDWebImage/SDImageCache.m index d1f44c59..57778cf5 100644 --- a/SDWebImage/SDImageCache.m +++ b/SDWebImage/SDImageCache.m @@ -336,12 +336,23 @@ BOOL ImageDataHasPNGPreffix(NSData *data) { } - (void)clearDisk { + [self clearDiskOnCompletion:nil]; +} + +- (void)clearDiskOnCompletion:(void (^)())completion +{ dispatch_async(self.ioQueue, ^{ [[NSFileManager defaultManager] removeItemAtPath:self.diskCachePath error:nil]; [[NSFileManager defaultManager] createDirectoryAtPath:self.diskCachePath withIntermediateDirectories:YES attributes:nil error:NULL]; + + if (completion) { + dispatch_main_sync_safe(^{ + completion(); + }); + } }); }