diff --git a/SDWebImage/SDImageCache.h b/SDWebImage/SDImageCache.h index 13391740..d3c92c17 100644 --- a/SDWebImage/SDImageCache.h +++ b/SDWebImage/SDImageCache.h @@ -26,14 +26,18 @@ typedef NS_ENUM(NSInteger, SDImageCacheType) { }; typedef NS_OPTIONS(NSUInteger, SDImageCacheOptions) { + /** + * By default, we will query disk cache if the memory cache missed. This mask can force to query memory cache only without disk data. + */ + SDImageCacheQueryMemoryOnly = 1 << 0, /** * 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. */ - SDImageCacheQueryDataWhenInMemory = 1 << 0, + SDImageCacheQueryDataWhenInMemory = 1 << 1, /** * By default, we query the memory cache synchronously, disk cache asynchronously. This mask can force to query disk cache synchronously. */ - SDImageCacheQueryDiskSync = 1 << 1 + SDImageCacheQueryDiskSync = 1 << 2 }; typedef void(^SDCacheQueryCompletedBlock)(UIImage * _Nullable image, NSData * _Nullable data, SDImageCacheType cacheType); diff --git a/SDWebImage/SDImageCache.m b/SDWebImage/SDImageCache.m index 03cd2f47..378f0106 100644 --- a/SDWebImage/SDImageCache.m +++ b/SDWebImage/SDImageCache.m @@ -356,7 +356,8 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { // First check the in-memory cache... UIImage *image = [self imageFromMemoryCacheForKey:key]; - if (image && !(options & SDImageCacheQueryDataWhenInMemory)) { + BOOL shouldQueryMemoryOnly = (options & SDImageCacheQueryMemoryOnly) || (image && !(options & SDImageCacheQueryDataWhenInMemory)); + if (shouldQueryMemoryOnly) { if (doneBlock) { doneBlock(image, nil, SDImageCacheTypeMemory); } diff --git a/SDWebImage/SDWebImageManager.h b/SDWebImage/SDWebImageManager.h index b5a810cd..02e313ca 100644 --- a/SDWebImage/SDWebImageManager.h +++ b/SDWebImage/SDWebImageManager.h @@ -25,7 +25,7 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) { SDWebImageLowPriority = 1 << 1, /** - * This flag disables on-disk caching + * This flag disables on-disk caching, including cache query and cache storing */ SDWebImageCacheMemoryOnly = 1 << 2, diff --git a/SDWebImage/SDWebImageManager.m b/SDWebImage/SDWebImageManager.m index 9696cf25..9e7e38c9 100644 --- a/SDWebImage/SDWebImageManager.m +++ b/SDWebImage/SDWebImageManager.m @@ -145,6 +145,7 @@ NSString *key = [self cacheKeyForURL:url]; SDImageCacheOptions cacheOptions = 0; + if (options & SDWebImageCacheMemoryOnly) cacheOptions |= SDImageCacheQueryMemoryOnly; if (options & SDWebImageQueryDataWhenInMemory) cacheOptions |= SDImageCacheQueryDataWhenInMemory; if (options & SDWebImageQueryDiskSync) cacheOptions |= SDImageCacheQueryDiskSync;