Expose the sync version of remove API

This commit is contained in:
DreamPiggy 2018-04-13 19:35:55 +08:00
parent 9f770b6c19
commit 1220f73507
2 changed files with 60 additions and 1 deletions

View File

@ -167,6 +167,15 @@ typedef NSString * _Nullable (^SDImageCacheAdditionalCachePathBlock)(NSString *
toDisk:(BOOL)toDisk
completion:(nullable SDWebImageNoParamsBlock)completionBlock;
/**
* Synchronously store image into memory cache at the given key.
*
* @param image The image to store
* @param key The unique image cache key, usually it's image absolute URL
*/
- (void)storeImageToMemory:(nullable UIImage*)image
forKey:(nullable NSString *)key;
/**
* Synchronously store image NSData into disk cache at the given key.
*
@ -177,7 +186,7 @@ typedef NSString * _Nullable (^SDImageCacheAdditionalCachePathBlock)(NSString *
forKey:(nullable NSString *)key;
#pragma mark - Query and Retrieve Ops
#pragma mark - Contains and Check Ops
/**
* Asynchronously check if image exists in disk cache already (does not load the image)
@ -195,6 +204,8 @@ typedef NSString * _Nullable (^SDImageCacheAdditionalCachePathBlock)(NSString *
*/
- (BOOL)diskImageDataExistsWithKey:(nullable NSString *)key;
#pragma mark - Query and Retrieve Ops
/**
* Asynchronously queries the cache with operation and call the completion when done.
*
@ -268,6 +279,20 @@ typedef NSString * _Nullable (^SDImageCacheAdditionalCachePathBlock)(NSString *
*/
- (void)removeImageForKey:(nullable NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(nullable SDWebImageNoParamsBlock)completion;
/**
Synchronously remove the image from memory cache.
@param key The unique image cache key
*/
- (void)removeImageFromMemoryForKey:(nullable NSString *)key;
/**
Synchronously remove the image from disk cache.
@param key The unique image cache key
*/
- (void)removeImageFromDiskForKey:(nullable NSString *)key;
#pragma mark - Cache clean Ops
/**

View File

@ -196,6 +196,14 @@
}
}
- (void)storeImageToMemory:(UIImage *)image forKey:(NSString *)key {
if (!image || !key) {
return;
}
NSUInteger cost = SDMemoryCacheCostForImage(image);
[self.memCache setObject:image forKey:key cost:cost];
}
- (void)storeImageDataToDisk:(nullable NSData *)imageData
forKey:(nullable NSString *)key {
if (!imageData || !key) {
@ -462,6 +470,32 @@
}
}
- (void)removeImageFromMemoryForKey:(NSString *)key {
if (!key) {
return;
}
[self.memCache removeObjectForKey:key];
}
- (void)removeImageFromDiskForKey:(NSString *)key {
if (!key) {
return;
}
dispatch_sync(self.ioQueue, ^{
[self _removeImageFromDiskForKey:key];
});
}
// Make sure to call form io queue by caller
- (void)_removeImageFromDiskForKey:(NSString *)key {
if (!key) {
return;
}
[self.diskCache removeDataForKey:key];
}
#pragma mark - Cache clean Ops
- (void)clearMemory {