Merge pull request #732 from dchohfi/master
#725 adding completition block when removing image from cache
Showing
2 changed files
with
39 additions
and
3 deletions
@@ -127,6 +127,15 @@ typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType ca | @@ -127,6 +127,15 @@ typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType ca | ||
127 | */ | 127 | */ |
128 | - (void)removeImageForKey:(NSString *)key; | 128 | - (void)removeImageForKey:(NSString *)key; |
129 | 129 | ||
130 | + | ||
131 | +/** | ||
132 | + * Remove the image from memory and disk cache synchronously | ||
133 | + * | ||
134 | + * @param key The unique image cache key | ||
135 | + * @param completionBlock An block that should be executed after the image has been removed (optional) | ||
136 | + */ | ||
137 | +- (void)removeImageForKey:(NSString *)key withCompletition:(void (^)())completion; | ||
138 | + | ||
130 | /** | 139 | /** |
131 | * Remove the image from memory and optionally disk cache synchronously | 140 | * Remove the image from memory and optionally disk cache synchronously |
132 | * | 141 | * |
@@ -136,6 +145,15 @@ typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType ca | @@ -136,6 +145,15 @@ typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType ca | ||
136 | - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk; | 145 | - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk; |
137 | 146 | ||
138 | /** | 147 | /** |
148 | + * Remove the image from memory and optionally disk cache synchronously | ||
149 | + * | ||
150 | + * @param key The unique image cache key | ||
151 | + * @param fromDisk Also remove cache entry from disk if YES | ||
152 | + * @param completionBlock An block that should be executed after the image has been removed (optional) | ||
153 | + */ | ||
154 | +- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletition:(void (^)())completion; | ||
155 | + | ||
156 | +/** | ||
139 | * Clear all memory cached images | 157 | * Clear all memory cached images |
140 | */ | 158 | */ |
141 | - (void)clearMemory; | 159 | - (void)clearMemory; |
@@ -303,21 +303,39 @@ BOOL ImageDataHasPNGPreffix(NSData *data) { | @@ -303,21 +303,39 @@ BOOL ImageDataHasPNGPreffix(NSData *data) { | ||
303 | } | 303 | } |
304 | 304 | ||
305 | - (void)removeImageForKey:(NSString *)key { | 305 | - (void)removeImageForKey:(NSString *)key { |
306 | - [self removeImageForKey:key fromDisk:YES]; | 306 | + [self removeImageForKey:key withCompletition:nil]; |
307 | +} | ||
308 | + | ||
309 | +- (void)removeImageForKey:(NSString *)key withCompletition:(void (^)())completion { | ||
310 | + [self removeImageForKey:key fromDisk:YES withCompletition:completion]; | ||
307 | } | 311 | } |
308 | 312 | ||
309 | - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk { | 313 | - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk { |
314 | + [self removeImageForKey:key fromDisk:fromDisk withCompletition:nil]; | ||
315 | +} | ||
316 | + | ||
317 | +- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletition:(void (^)())completion { | ||
318 | + | ||
310 | if (key == nil) { | 319 | if (key == nil) { |
311 | return; | 320 | return; |
312 | } | 321 | } |
313 | - | 322 | + |
314 | [self.memCache removeObjectForKey:key]; | 323 | [self.memCache removeObjectForKey:key]; |
315 | - | 324 | + |
316 | if (fromDisk) { | 325 | if (fromDisk) { |
317 | dispatch_async(self.ioQueue, ^{ | 326 | dispatch_async(self.ioQueue, ^{ |
318 | [_fileManager removeItemAtPath:[self defaultCachePathForKey:key] error:nil]; | 327 | [_fileManager removeItemAtPath:[self defaultCachePathForKey:key] error:nil]; |
328 | + | ||
329 | + if (completion) { | ||
330 | + dispatch_async(dispatch_get_main_queue(), ^{ | ||
331 | + completion(); | ||
332 | + }); | ||
333 | + } | ||
319 | }); | 334 | }); |
335 | + } else if (completion){ | ||
336 | + completion(); | ||
320 | } | 337 | } |
338 | + | ||
321 | } | 339 | } |
322 | 340 | ||
323 | - (void)setMaxMemoryCost:(NSUInteger)maxMemoryCost { | 341 | - (void)setMaxMemoryCost:(NSUInteger)maxMemoryCost { |
-
Please register or login to post a comment