Skip to content

Commit

Permalink
Merge pull request #638 from limbo-lab/master
Browse files Browse the repository at this point in the history
added clearDiskOnCompletion
  • Loading branch information
Olivier Poitrey committed Feb 18, 2014
2 parents 1b394c1 + 1d8bfa6 commit 657bd81
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions SDWebImage/SDImageCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions SDWebImage/SDImageCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,23 @@ - (void)clearMemory {
}

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

Expand Down

0 comments on commit 657bd81

Please sign in to comment.