Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#725 adding completition block when removing image from cache #732

Merged
merged 1 commit into from
Jun 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions SDWebImage/SDImageCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -135,6 +144,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
*/
Expand Down
24 changes: 21 additions & 3 deletions SDWebImage/SDImageCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -303,21 +303,39 @@ - (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(void (^)(UIImage *im
}

- (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 {
Expand Down