Authored by Bogdan Poplauschi

Merge pull request #732 from dchohfi/master

#725 adding completition block when removing image from cache
... ... @@ -127,6 +127,15 @@ typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType ca
*/
- (void)removeImageForKey:(NSString *)key;
/**
* Remove the image from memory and disk cache synchronously
*
* @param key The unique image cache key
* @param completionBlock An block that should be executed after the image has been removed (optional)
*/
- (void)removeImageForKey:(NSString *)key withCompletition:(void (^)())completion;
/**
* Remove the image from memory and optionally disk cache synchronously
*
... ... @@ -136,6 +145,15 @@ typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType ca
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk;
/**
* Remove the image from memory and optionally disk cache synchronously
*
* @param key The unique image cache key
* @param fromDisk Also remove cache entry from disk if YES
* @param completionBlock An block that should be executed after the image has been removed (optional)
*/
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletition:(void (^)())completion;
/**
* Clear all memory cached images
*/
- (void)clearMemory;
... ...
... ... @@ -303,21 +303,39 @@ BOOL ImageDataHasPNGPreffix(NSData *data) {
}
- (void)removeImageForKey:(NSString *)key {
[self removeImageForKey:key fromDisk:YES];
[self removeImageForKey:key withCompletition:nil];
}
- (void)removeImageForKey:(NSString *)key withCompletition:(void (^)())completion {
[self removeImageForKey:key fromDisk:YES withCompletition:completion];
}
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk {
[self removeImageForKey:key fromDisk:fromDisk withCompletition:nil];
}
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletition:(void (^)())completion {
if (key == nil) {
return;
}
[self.memCache removeObjectForKey:key];
if (fromDisk) {
dispatch_async(self.ioQueue, ^{
[_fileManager removeItemAtPath:[self defaultCachePathForKey:key] error:nil];
if (completion) {
dispatch_async(dispatch_get_main_queue(), ^{
completion();
});
}
});
} else if (completion){
completion();
}
}
- (void)setMaxMemoryCost:(NSUInteger)maxMemoryCost {
... ...