Merge pull request #638 from limbo-lab/master

added clearDiskOnCompletion
This commit is contained in:
Olivier Poitrey 2014-02-18 00:27:53 -08:00
commit 657bd81658
2 changed files with 12 additions and 0 deletions

View File

@ -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

View File

@ -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();
});
}
});
}