Authored by DreamPiggy

Add the SDImageCacheQueryMemoryOnly to specify query memory only

@@ -27,13 +27,17 @@ typedef NS_ENUM(NSInteger, SDImageCacheType) { @@ -27,13 +27,17 @@ typedef NS_ENUM(NSInteger, SDImageCacheType) {
27 27
28 typedef NS_OPTIONS(NSUInteger, SDImageCacheOptions) { 28 typedef NS_OPTIONS(NSUInteger, SDImageCacheOptions) {
29 /** 29 /**
  30 + * By default, we will query disk cache if the memory cache missed. This mask can force to query memory cache only without disk data.
  31 + */
  32 + SDImageCacheQueryMemoryOnly = 1 << 0,
  33 + /**
30 * By default, we do not query disk data when the image is cached in memory. This mask can force to query disk data at the same time. 34 * By default, we do not query disk data when the image is cached in memory. This mask can force to query disk data at the same time.
31 */ 35 */
32 - SDImageCacheQueryDataWhenInMemory = 1 << 0, 36 + SDImageCacheQueryDataWhenInMemory = 1 << 1,
33 /** 37 /**
34 * By default, we query the memory cache synchronously, disk cache asynchronously. This mask can force to query disk cache synchronously. 38 * By default, we query the memory cache synchronously, disk cache asynchronously. This mask can force to query disk cache synchronously.
35 */ 39 */
36 - SDImageCacheQueryDiskSync = 1 << 1 40 + SDImageCacheQueryDiskSync = 1 << 2
37 }; 41 };
38 42
39 typedef void(^SDCacheQueryCompletedBlock)(UIImage * _Nullable image, NSData * _Nullable data, SDImageCacheType cacheType); 43 typedef void(^SDCacheQueryCompletedBlock)(UIImage * _Nullable image, NSData * _Nullable data, SDImageCacheType cacheType);
@@ -356,7 +356,8 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { @@ -356,7 +356,8 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
356 356
357 // First check the in-memory cache... 357 // First check the in-memory cache...
358 UIImage *image = [self imageFromMemoryCacheForKey:key]; 358 UIImage *image = [self imageFromMemoryCacheForKey:key];
359 - if (image && !(options & SDImageCacheQueryDataWhenInMemory)) { 359 + BOOL shouldQueryMemoryOnly = (options & SDImageCacheQueryMemoryOnly) || (image && !(options & SDImageCacheQueryDataWhenInMemory));
  360 + if (shouldQueryMemoryOnly) {
360 if (doneBlock) { 361 if (doneBlock) {
361 doneBlock(image, nil, SDImageCacheTypeMemory); 362 doneBlock(image, nil, SDImageCacheTypeMemory);
362 } 363 }
@@ -25,7 +25,7 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) { @@ -25,7 +25,7 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {
25 SDWebImageLowPriority = 1 << 1, 25 SDWebImageLowPriority = 1 << 1,
26 26
27 /** 27 /**
28 - * This flag disables on-disk caching 28 + * This flag disables on-disk caching, including cache query and cache storing
29 */ 29 */
30 SDWebImageCacheMemoryOnly = 1 << 2, 30 SDWebImageCacheMemoryOnly = 1 << 2,
31 31
@@ -145,6 +145,7 @@ @@ -145,6 +145,7 @@
145 NSString *key = [self cacheKeyForURL:url]; 145 NSString *key = [self cacheKeyForURL:url];
146 146
147 SDImageCacheOptions cacheOptions = 0; 147 SDImageCacheOptions cacheOptions = 0;
  148 + if (options & SDWebImageCacheMemoryOnly) cacheOptions |= SDImageCacheQueryMemoryOnly;
148 if (options & SDWebImageQueryDataWhenInMemory) cacheOptions |= SDImageCacheQueryDataWhenInMemory; 149 if (options & SDWebImageQueryDataWhenInMemory) cacheOptions |= SDImageCacheQueryDataWhenInMemory;
149 if (options & SDWebImageQueryDiskSync) cacheOptions |= SDImageCacheQueryDiskSync; 150 if (options & SDWebImageQueryDiskSync) cacheOptions |= SDImageCacheQueryDiskSync;
150 151