|
@@ -275,6 +275,8 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { |
|
@@ -275,6 +275,8 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { |
275
|
});
|
275
|
});
|
276
|
}
|
276
|
}
|
277
|
|
277
|
|
|
|
278
|
+#pragma mark - Query Ops
|
|
|
279
|
+
|
278
|
- (nullable UIImage *)imageFromMemoryCacheForKey:(nullable NSString *)key {
|
280
|
- (nullable UIImage *)imageFromMemoryCacheForKey:(nullable NSString *)key {
|
279
|
return [self.memCache objectForKey:key];
|
281
|
return [self.memCache objectForKey:key];
|
280
|
}
|
282
|
}
|
|
@@ -354,12 +356,10 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { |
|
@@ -354,12 +356,10 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { |
354
|
}
|
356
|
}
|
355
|
|
357
|
|
356
|
- (nullable NSOperation *)queryCacheOperationForKey:(nullable NSString *)key done:(nullable SDCacheQueryCompletedBlock)doneBlock {
|
358
|
- (nullable NSOperation *)queryCacheOperationForKey:(nullable NSString *)key done:(nullable SDCacheQueryCompletedBlock)doneBlock {
|
357
|
- if (!doneBlock) {
|
|
|
358
|
- return nil;
|
|
|
359
|
- }
|
|
|
360
|
-
|
|
|
361
|
if (!key) {
|
359
|
if (!key) {
|
362
|
- doneBlock(nil, nil, SDImageCacheTypeNone);
|
360
|
+ if (doneBlock) {
|
|
|
361
|
+ doneBlock(nil, nil, SDImageCacheTypeNone);
|
|
|
362
|
+ }
|
363
|
return nil;
|
363
|
return nil;
|
364
|
}
|
364
|
}
|
365
|
|
365
|
|
|
@@ -370,13 +370,16 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { |
|
@@ -370,13 +370,16 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { |
370
|
if ([image isGIF]) {
|
370
|
if ([image isGIF]) {
|
371
|
diskData = [self diskImageDataBySearchingAllPathsForKey:key];
|
371
|
diskData = [self diskImageDataBySearchingAllPathsForKey:key];
|
372
|
}
|
372
|
}
|
373
|
- doneBlock(image, diskData, SDImageCacheTypeMemory);
|
373
|
+ if (doneBlock) {
|
|
|
374
|
+ doneBlock(image, diskData, SDImageCacheTypeMemory);
|
|
|
375
|
+ }
|
374
|
return nil;
|
376
|
return nil;
|
375
|
}
|
377
|
}
|
376
|
|
378
|
|
377
|
NSOperation *operation = [NSOperation new];
|
379
|
NSOperation *operation = [NSOperation new];
|
378
|
dispatch_async(self.ioQueue, ^{
|
380
|
dispatch_async(self.ioQueue, ^{
|
379
|
if (operation.isCancelled) {
|
381
|
if (operation.isCancelled) {
|
|
|
382
|
+ // do not call the completion if cancelled
|
380
|
return;
|
383
|
return;
|
381
|
}
|
384
|
}
|
382
|
|
385
|
|
|
@@ -388,9 +391,11 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { |
|
@@ -388,9 +391,11 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { |
388
|
[self.memCache setObject:diskImage forKey:key cost:cost];
|
391
|
[self.memCache setObject:diskImage forKey:key cost:cost];
|
389
|
}
|
392
|
}
|
390
|
|
393
|
|
391
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
392
|
- doneBlock(diskImage, diskData, SDImageCacheTypeDisk);
|
|
|
393
|
- });
|
394
|
+ if (doneBlock) {
|
|
|
395
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
396
|
+ doneBlock(diskImage, diskData, SDImageCacheTypeDisk);
|
|
|
397
|
+ });
|
|
|
398
|
+ }
|
394
|
}
|
399
|
}
|
395
|
});
|
400
|
});
|
396
|
|
401
|
|