From 1d8bfa6064fe05f2435c5d7b2593f566c11be7c6 Mon Sep 17 00:00:00 2001 From: limbo-lab Date: Tue, 18 Feb 2014 15:30:14 +0800 Subject: [PATCH] added clearDiskOnCompletion --- SDWebImage/SDImageCache.h | 1 + SDWebImage/SDImageCache.m | 11 +++++++++++ 2 files changed, 12 insertions(+) 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(); + }); + } }); }