Updated `queryCacheOperationForKey:image:` comments and method still works if the doneBlock is nil
This commit is contained in:
parent
d9424345ab
commit
f202b50330
|
@ -146,11 +146,13 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
|||
*/
|
||||
- (void)storeImageDataToDisk:(nullable NSData *)imageData forKey:(nullable NSString *)key;
|
||||
|
||||
#pragma mark - Query Ops
|
||||
|
||||
/**
|
||||
* Query the cache asynchronously and call the completion when done.
|
||||
* Operation that queries the cache asynchronously and call the completion when done.
|
||||
*
|
||||
* @param key The unique key used to store the wanted image
|
||||
* @param doneBlock The completion block
|
||||
* @param doneBlock The completion block. Will not get called if the operation is cancelled
|
||||
*
|
||||
* @return a NSOperation instance containing the cache op
|
||||
*/
|
||||
|
|
|
@ -275,6 +275,8 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
|||
});
|
||||
}
|
||||
|
||||
#pragma mark - Query Ops
|
||||
|
||||
- (nullable UIImage *)imageFromMemoryCacheForKey:(nullable NSString *)key {
|
||||
return [self.memCache objectForKey:key];
|
||||
}
|
||||
|
@ -354,12 +356,10 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
|||
}
|
||||
|
||||
- (nullable NSOperation *)queryCacheOperationForKey:(nullable NSString *)key done:(nullable SDCacheQueryCompletedBlock)doneBlock {
|
||||
if (!doneBlock) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (!key) {
|
||||
if (doneBlock) {
|
||||
doneBlock(nil, nil, SDImageCacheTypeNone);
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
@ -370,13 +370,16 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
|||
if ([image isGIF]) {
|
||||
diskData = [self diskImageDataBySearchingAllPathsForKey:key];
|
||||
}
|
||||
if (doneBlock) {
|
||||
doneBlock(image, diskData, SDImageCacheTypeMemory);
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSOperation *operation = [NSOperation new];
|
||||
dispatch_async(self.ioQueue, ^{
|
||||
if (operation.isCancelled) {
|
||||
// do not call the completion if cancelled
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -388,10 +391,12 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
|||
[self.memCache setObject:diskImage forKey:key cost:cost];
|
||||
}
|
||||
|
||||
if (doneBlock) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
doneBlock(diskImage, diskData, SDImageCacheTypeDisk);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return operation;
|
||||
|
|
Loading…
Reference in New Issue