@@ -619,7 +619,8 @@ - (nullable SDImageCacheToken *)queryCacheOperationForKey:(nullable NSString *)k |
619 | 619 |
|
620 | 620 | // First check the in-memory cache... |
621 | 621 | UIImage *image; |
622 | | - if (queryCacheType != SDImageCacheTypeDisk) { |
| 622 | + BOOL shouldQueryDiskOnly = (queryCacheType == SDImageCacheTypeDisk); |
| 623 | + if (!shouldQueryDiskOnly) { |
623 | 624 | image = [self imageFromMemoryCacheForKey:key]; |
624 | 625 | } |
625 | 626 |
|
@@ -683,14 +684,19 @@ - (nullable SDImageCacheToken *)queryCacheOperationForKey:(nullable NSString *)k |
683 | 684 | // the image is from in-memory cache, but need image data |
684 | 685 | diskImage = image; |
685 | 686 | } else if (diskData) { |
| 687 | + // the image memory cache miss, need image data and image |
686 | 688 | BOOL shouldCacheToMemory = YES; |
687 | 689 | if (context[SDWebImageContextStoreCacheType]) { |
688 | 690 | SDImageCacheType cacheType = [context[SDWebImageContextStoreCacheType] integerValue]; |
689 | 691 | shouldCacheToMemory = (cacheType == SDImageCacheTypeAll || cacheType == SDImageCacheTypeMemory); |
690 | 692 | } |
691 | | - // Special case: If user query image in list for the same URL, to avoid decode and write **same** image object into disk cache multiple times, we query and check memory cache here again. |
692 | | - if (shouldCacheToMemory && self.config.shouldCacheImagesInMemory) { |
693 | | - diskImage = [self.memoryCache objectForKey:key]; |
| 693 | + // Special case: If user query image in list for the same URL, to avoid decode and write **same** image object into disk cache multiple times, we query and check memory cache here again. See: #3523 |
| 694 | + // This because disk operation can be async, previous sync check of `memory cache miss`, does not gurantee current check of `memory cache miss` |
| 695 | + if (!shouldQueryDiskSync) { |
| 696 | + // First check the in-memory cache... |
| 697 | + if (!shouldQueryDiskOnly) { |
| 698 | + diskImage = [self imageFromMemoryCacheForKey:key]; |
| 699 | + } |
694 | 700 | } |
695 | 701 | // decode image data only if in-memory cache missed |
696 | 702 | if (!diskImage) { |
|