From 734c6821d5a55f988f1a28192b3ac347cba5cd2f Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Wed, 18 Apr 2018 19:16:45 +0800 Subject: [PATCH] Rename the cache protocol to `SDImageCache` protocol --- SDWebImage.xcodeproj/project.pbxproj | 56 ++++++------- SDWebImage/SDImageCache.h | 12 +-- ...SDWebImageCache.h => SDImageCacheDefine.h} | 5 +- ...SDWebImageCache.m => SDImageCacheDefine.m} | 2 +- SDWebImage/SDImageCachesManager.h | 10 +-- SDWebImage/SDImageCachesManager.m | 82 +++++++++---------- SDWebImage/SDWebImageManager.h | 8 +- SDWebImage/SDWebImageManager.m | 12 +-- 8 files changed, 92 insertions(+), 95 deletions(-) rename SDWebImage/{SDWebImageCache.h => SDImageCacheDefine.h} (95%) rename SDWebImage/{SDWebImageCache.m => SDImageCacheDefine.m} (98%) diff --git a/SDWebImage.xcodeproj/project.pbxproj b/SDWebImage.xcodeproj/project.pbxproj index 695866a7..ee9d0625 100644 --- a/SDWebImage.xcodeproj/project.pbxproj +++ b/SDWebImage.xcodeproj/project.pbxproj @@ -508,18 +508,18 @@ 32CF1C101FA496B000004BD1 /* SDWebImageCoderHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 32CF1C061FA496B000004BD1 /* SDWebImageCoderHelper.m */; }; 32CF1C111FA496B000004BD1 /* SDWebImageCoderHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 32CF1C061FA496B000004BD1 /* SDWebImageCoderHelper.m */; }; 32CF1C121FA496B000004BD1 /* SDWebImageCoderHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 32CF1C061FA496B000004BD1 /* SDWebImageCoderHelper.m */; }; - 32D1221E2080B2EB003685A3 /* SDWebImageCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 32D1221A2080B2EB003685A3 /* SDWebImageCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 32D1221F2080B2EB003685A3 /* SDWebImageCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 32D1221A2080B2EB003685A3 /* SDWebImageCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 32D122202080B2EB003685A3 /* SDWebImageCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 32D1221A2080B2EB003685A3 /* SDWebImageCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 32D122212080B2EB003685A3 /* SDWebImageCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 32D1221A2080B2EB003685A3 /* SDWebImageCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 32D122222080B2EB003685A3 /* SDWebImageCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 32D1221A2080B2EB003685A3 /* SDWebImageCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 32D122232080B2EB003685A3 /* SDWebImageCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 32D1221A2080B2EB003685A3 /* SDWebImageCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 32D122242080B2EB003685A3 /* SDWebImageCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D1221B2080B2EB003685A3 /* SDWebImageCache.m */; }; - 32D122252080B2EB003685A3 /* SDWebImageCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D1221B2080B2EB003685A3 /* SDWebImageCache.m */; }; - 32D122262080B2EB003685A3 /* SDWebImageCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D1221B2080B2EB003685A3 /* SDWebImageCache.m */; }; - 32D122272080B2EB003685A3 /* SDWebImageCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D1221B2080B2EB003685A3 /* SDWebImageCache.m */; }; - 32D122282080B2EB003685A3 /* SDWebImageCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D1221B2080B2EB003685A3 /* SDWebImageCache.m */; }; - 32D122292080B2EB003685A3 /* SDWebImageCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D1221B2080B2EB003685A3 /* SDWebImageCache.m */; }; + 32D1221E2080B2EB003685A3 /* SDImageCacheDefine.h in Headers */ = {isa = PBXBuildFile; fileRef = 32D1221A2080B2EB003685A3 /* SDImageCacheDefine.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 32D1221F2080B2EB003685A3 /* SDImageCacheDefine.h in Headers */ = {isa = PBXBuildFile; fileRef = 32D1221A2080B2EB003685A3 /* SDImageCacheDefine.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 32D122202080B2EB003685A3 /* SDImageCacheDefine.h in Headers */ = {isa = PBXBuildFile; fileRef = 32D1221A2080B2EB003685A3 /* SDImageCacheDefine.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 32D122212080B2EB003685A3 /* SDImageCacheDefine.h in Headers */ = {isa = PBXBuildFile; fileRef = 32D1221A2080B2EB003685A3 /* SDImageCacheDefine.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 32D122222080B2EB003685A3 /* SDImageCacheDefine.h in Headers */ = {isa = PBXBuildFile; fileRef = 32D1221A2080B2EB003685A3 /* SDImageCacheDefine.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 32D122232080B2EB003685A3 /* SDImageCacheDefine.h in Headers */ = {isa = PBXBuildFile; fileRef = 32D1221A2080B2EB003685A3 /* SDImageCacheDefine.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 32D122242080B2EB003685A3 /* SDImageCacheDefine.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D1221B2080B2EB003685A3 /* SDImageCacheDefine.m */; }; + 32D122252080B2EB003685A3 /* SDImageCacheDefine.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D1221B2080B2EB003685A3 /* SDImageCacheDefine.m */; }; + 32D122262080B2EB003685A3 /* SDImageCacheDefine.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D1221B2080B2EB003685A3 /* SDImageCacheDefine.m */; }; + 32D122272080B2EB003685A3 /* SDImageCacheDefine.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D1221B2080B2EB003685A3 /* SDImageCacheDefine.m */; }; + 32D122282080B2EB003685A3 /* SDImageCacheDefine.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D1221B2080B2EB003685A3 /* SDImageCacheDefine.m */; }; + 32D122292080B2EB003685A3 /* SDImageCacheDefine.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D1221B2080B2EB003685A3 /* SDImageCacheDefine.m */; }; 32D1222A2080B2EB003685A3 /* SDImageCachesManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D1221C2080B2EB003685A3 /* SDImageCachesManager.m */; }; 32D1222B2080B2EB003685A3 /* SDImageCachesManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D1221C2080B2EB003685A3 /* SDImageCachesManager.m */; }; 32D1222C2080B2EB003685A3 /* SDImageCachesManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D1221C2080B2EB003685A3 /* SDImageCachesManager.m */; }; @@ -1596,8 +1596,8 @@ 32C0FDE02013426C001B8F2D /* SDWebImageIndicator.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDWebImageIndicator.m; sourceTree = ""; }; 32CF1C051FA496B000004BD1 /* SDWebImageCoderHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDWebImageCoderHelper.h; sourceTree = ""; }; 32CF1C061FA496B000004BD1 /* SDWebImageCoderHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDWebImageCoderHelper.m; sourceTree = ""; }; - 32D1221A2080B2EB003685A3 /* SDWebImageCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDWebImageCache.h; sourceTree = ""; }; - 32D1221B2080B2EB003685A3 /* SDWebImageCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageCache.m; sourceTree = ""; }; + 32D1221A2080B2EB003685A3 /* SDImageCacheDefine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDImageCacheDefine.h; sourceTree = ""; }; + 32D1221B2080B2EB003685A3 /* SDImageCacheDefine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDImageCacheDefine.m; sourceTree = ""; }; 32D1221C2080B2EB003685A3 /* SDImageCachesManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDImageCachesManager.m; sourceTree = ""; }; 32D1221D2080B2EB003685A3 /* SDImageCachesManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDImageCachesManager.h; sourceTree = ""; }; 32F21B4F20788D8C0036B1D5 /* SDWebImageDownloaderRequestModifier.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDWebImageDownloaderRequestModifier.h; sourceTree = ""; }; @@ -2118,8 +2118,8 @@ 328BB6C02082581100760D6C /* SDMemoryCache.m */, 328BB6BD2082581100760D6C /* SDDiskCache.h */, 328BB6BE2082581100760D6C /* SDDiskCache.m */, - 32D1221A2080B2EB003685A3 /* SDWebImageCache.h */, - 32D1221B2080B2EB003685A3 /* SDWebImageCache.m */, + 32D1221A2080B2EB003685A3 /* SDImageCacheDefine.h */, + 32D1221B2080B2EB003685A3 /* SDImageCacheDefine.m */, 32D1221D2080B2EB003685A3 /* SDImageCachesManager.h */, 32D1221C2080B2EB003685A3 /* SDImageCachesManager.m */, ); @@ -2342,7 +2342,7 @@ 323F8B531F38EF770092B609 /* backward_references_enc.h in Headers */, 4317395A1CDFC8B70008FEB9 /* mux_types.h in Headers */, 431739561CDFC8B70008FEB9 /* demux.h in Headers */, - 32D122212080B2EB003685A3 /* SDWebImageCache.h in Headers */, + 32D122212080B2EB003685A3 /* SDImageCacheDefine.h in Headers */, 32B9B53A206ED4230026769D /* SDWebImageDownloaderConfig.h in Headers */, 328BB6AD2081FEE500760D6C /* SDWebImageCacheSerializer.h in Headers */, 80377C4A1F2F666300F89830 /* bit_writer_utils.h in Headers */, @@ -2440,7 +2440,7 @@ 80377C1D1F2F666300F89830 /* huffman_encode_utils.h in Headers */, 321E60B11F38E90100405457 /* SDWebImageWebPCoder.h in Headers */, 80377E9A1F2F66D400F89830 /* common_dec.h in Headers */, - 32D1221F2080B2EB003685A3 /* SDWebImageCache.h in Headers */, + 32D1221F2080B2EB003685A3 /* SDImageCacheDefine.h in Headers */, 327054D5206CD8B3006EA328 /* SDWebImageAPNGCoder.h in Headers */, 328BB6AB2081FEE500760D6C /* SDWebImageCacheSerializer.h in Headers */, 32B9B538206ED4230026769D /* SDWebImageDownloaderConfig.h in Headers */, @@ -2609,7 +2609,7 @@ 32F7C0732030114C00873181 /* SDWebImageTransformer.h in Headers */, 431BB6FA1D06D2C1006A3455 /* SDWebImageDownloader.h in Headers */, 3248476D201775F600AF9E5A /* SDAnimatedImageView.h in Headers */, - 32D122222080B2EB003685A3 /* SDWebImageCache.h in Headers */, + 32D122222080B2EB003685A3 /* SDImageCacheDefine.h in Headers */, 80377DF51F2F66A800F89830 /* common_sse2.h in Headers */, 323F8BDC1F38EF770092B609 /* vp8i_enc.h in Headers */, 80377ED21F2F66D500F89830 /* vp8i_dec.h in Headers */, @@ -2630,7 +2630,7 @@ 32F7C0892030719600873181 /* UIImage+Transform.h in Headers */, 80377EDA1F2F66D500F89830 /* common_dec.h in Headers */, 80377EE61F2F66D500F89830 /* webpi_dec.h in Headers */, - 32D122232080B2EB003685A3 /* SDWebImageCache.h in Headers */, + 32D122232080B2EB003685A3 /* SDImageCacheDefine.h in Headers */, 32B9B53C206ED4230026769D /* SDWebImageDownloaderConfig.h in Headers */, 328BB6AF2081FEE500760D6C /* SDWebImageCacheSerializer.h in Headers */, 4397D2BA1D0DDD8C00BB2784 /* demux.h in Headers */, @@ -2729,7 +2729,7 @@ 323F8B521F38EF770092B609 /* backward_references_enc.h in Headers */, 4317394F1CDFC8B70008FEB9 /* demux.h in Headers */, 43CE757D1CFE9427006C64D0 /* FLAnimatedImageView.h in Headers */, - 32D122202080B2EB003685A3 /* SDWebImageCache.h in Headers */, + 32D122202080B2EB003685A3 /* SDImageCacheDefine.h in Headers */, 32B9B539206ED4230026769D /* SDWebImageDownloaderConfig.h in Headers */, 328BB6AC2081FEE500760D6C /* SDWebImageCacheSerializer.h in Headers */, 80377C301F2F666300F89830 /* bit_writer_utils.h in Headers */, @@ -2901,7 +2901,7 @@ 323F8B6E1F38EF770092B609 /* delta_palettization_enc.h in Headers */, 438096721CDFC08200DC626B /* MKAnnotationView+WebCache.h in Headers */, 43CE757C1CFE9427006C64D0 /* FLAnimatedImageView.h in Headers */, - 32D1221E2080B2EB003685A3 /* SDWebImageCache.h in Headers */, + 32D1221E2080B2EB003685A3 /* SDImageCacheDefine.h in Headers */, 80377E8A1F2F66D000F89830 /* common_dec.h in Headers */, AB615303192DA24600A2D8E9 /* UIView+WebCacheOperation.h in Headers */, 323F8B501F38EF770092B609 /* backward_references_enc.h in Headers */, @@ -3261,7 +3261,7 @@ 80377DB51F2F66A700F89830 /* cpu.c in Sources */, 80377EC51F2F66D500F89830 /* webp_dec.c in Sources */, 80377DD61F2F66A700F89830 /* lossless_neon.c in Sources */, - 32D122272080B2EB003685A3 /* SDWebImageCache.m in Sources */, + 32D122272080B2EB003685A3 /* SDImageCacheDefine.m in Sources */, 00733A5C1BC4880000A5A117 /* UIButton+WebCache.m in Sources */, 80377EC01F2F66D500F89830 /* vp8_dec.c in Sources */, 80377C521F2F666300F89830 /* huffman_utils.c in Sources */, @@ -3345,7 +3345,7 @@ 4314D1341D0E0E3B004B36C9 /* UIImage+WebP.m in Sources */, 80377D3D1F2F66A700F89830 /* filters_mips_dsp_r2.c in Sources */, 323F8B751F38EF770092B609 /* filter_enc.c in Sources */, - 32D122252080B2EB003685A3 /* SDWebImageCache.m in Sources */, + 32D122252080B2EB003685A3 /* SDImageCacheDefine.m in Sources */, 80377D401F2F66A700F89830 /* filters_sse2.c in Sources */, 80377D1E1F2F66A700F89830 /* alpha_processing_mips_dsp_r2.c in Sources */, 80377D291F2F66A700F89830 /* cost_sse2.c in Sources */, @@ -3509,7 +3509,7 @@ 323F8BE21F38EF770092B609 /* vp8l_enc.c in Sources */, 431BB6A31D06D2C1006A3455 /* UIImageView+WebCache.m in Sources */, 80377E0C1F2F66A800F89830 /* filters_mips_dsp_r2.c in Sources */, - 32D122282080B2EB003685A3 /* SDWebImageCache.m in Sources */, + 32D122282080B2EB003685A3 /* SDImageCacheDefine.m in Sources */, 323F8B781F38EF770092B609 /* filter_enc.c in Sources */, 4369C2821D9807EC007E863A /* UIView+WebCache.m in Sources */, 80377E0F1F2F66A800F89830 /* filters_sse2.c in Sources */, @@ -3705,7 +3705,7 @@ 80377E381F2F66A800F89830 /* argb_sse2.c in Sources */, 323F8B9B1F38EF770092B609 /* near_lossless_enc.c in Sources */, 32F21B5C20788D8C0036B1D5 /* SDWebImageDownloaderRequestModifier.m in Sources */, - 32D122292080B2EB003685A3 /* SDWebImageCache.m in Sources */, + 32D122292080B2EB003685A3 /* SDImageCacheDefine.m in Sources */, 80377E3B1F2F66A800F89830 /* cost_mips_dsp_r2.c in Sources */, 4397D29B1D0DDD8C00BB2784 /* SDWebImageDownloader.m in Sources */, 80377E711F2F66A800F89830 /* upsampling.c in Sources */, @@ -3923,7 +3923,7 @@ 80377D8C1F2F66A700F89830 /* lossless_enc_sse2.c in Sources */, 4A2CAE2C1AB4BB7500B6BC39 /* UIButton+WebCache.m in Sources */, 80377EB51F2F66D400F89830 /* webp_dec.c in Sources */, - 32D122262080B2EB003685A3 /* SDWebImageCache.m in Sources */, + 32D122262080B2EB003685A3 /* SDImageCacheDefine.m in Sources */, 80377D701F2F66A700F89830 /* cpu.c in Sources */, 80377D911F2F66A700F89830 /* lossless_neon.c in Sources */, 80377EB01F2F66D400F89830 /* vp8_dec.c in Sources */, @@ -4091,7 +4091,7 @@ A18A6CC9172DC28500419892 /* UIImage+GIF.m in Sources */, 80377E951F2F66D000F89830 /* webp_dec.c in Sources */, 80377CE61F2F66A100F89830 /* cpu.c in Sources */, - 32D122242080B2EB003685A3 /* SDWebImageCache.m in Sources */, + 32D122242080B2EB003685A3 /* SDImageCacheDefine.m in Sources */, 80377D071F2F66A100F89830 /* lossless_neon.c in Sources */, 80377E901F2F66D000F89830 /* vp8_dec.c in Sources */, 80377C041F2F665300F89830 /* huffman_utils.c in Sources */, diff --git a/SDWebImage/SDImageCache.h b/SDWebImage/SDImageCache.h index a1f4b971..e70c280f 100644 --- a/SDWebImage/SDImageCache.h +++ b/SDWebImage/SDImageCache.h @@ -10,7 +10,7 @@ #import "SDWebImageCompat.h" #import "SDWebImageDefine.h" #import "SDImageCacheConfig.h" -#import "SDWebImageCache.h" +#import "SDImageCacheDefine.h" typedef NS_OPTIONS(NSUInteger, SDImageCacheOptions) { /** @@ -46,14 +46,8 @@ typedef NS_OPTIONS(NSUInteger, SDImageCacheOptions) { SDImageCachePreloadAllFrames = 1 << 6 }; -typedef void(^SDImageCacheCheckCompletionBlock)(BOOL isInCache); - -typedef void(^SDImageCacheCalculateSizeBlock)(NSUInteger fileCount, NSUInteger totalSize); - -typedef NSString * _Nullable (^SDImageCacheAdditionalCachePathBlock)(NSString * _Nonnull key); - /** - * SDImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed + * SDImageCache maintains a memory cache and a disk cache. Disk cache write operations are performed * asynchronous so it doesn’t add unnecessary latency to the UI. */ @interface SDImageCache : NSObject @@ -332,6 +326,6 @@ typedef NSString * _Nullable (^SDImageCacheAdditionalCachePathBlock)(NSString * /** * SDImageCache is the built-in image cache implementation for web image manager. It adopts `SDWebImageCache` protocol to provide the function for web image manager to use for image loading process. */ -@interface SDImageCache (SDWebImageCache) +@interface SDImageCache (SDWebImageCache) @end diff --git a/SDWebImage/SDWebImageCache.h b/SDWebImage/SDImageCacheDefine.h similarity index 95% rename from SDWebImage/SDWebImageCache.h rename to SDWebImage/SDImageCacheDefine.h index c5aeb0b4..caf186ed 100644 --- a/SDWebImage/SDWebImageCache.h +++ b/SDWebImage/SDImageCacheDefine.h @@ -34,6 +34,9 @@ typedef NS_ENUM(NSInteger, SDImageCacheType) { SDImageCacheTypeAll }; +typedef void(^SDImageCacheCheckCompletionBlock)(BOOL isInCache); +typedef void(^SDImageCacheCalculateSizeBlock)(NSUInteger fileCount, NSUInteger totalSize); +typedef NSString * _Nullable (^SDImageCacheAdditionalCachePathBlock)(NSString * _Nonnull key); typedef void(^SDImageCacheQueryCompletionBlock)(UIImage * _Nullable image, NSData * _Nullable data, SDImageCacheType cacheType); typedef void(^SDImageCacheContainsCompletionBlock)(SDImageCacheType containsCacheType); @@ -54,7 +57,7 @@ FOUNDATION_EXPORT UIImage * _Nullable SDWebImageCacheDecodeImageData(NSData * _N Though the best practice to custom image cache, is to write your own class which conform `SDMemoryCache` or `SDDiskCache` protocol for `SDImageCache` class (See more on `SDImageCacheConfig.memoryCacheClass & SDImageCacheConfig.diskCacheClass`). However, if your own cache implementation contains more advanced feature beyond `SDImageCache` itself, you can consider to provide this instead. For example, you can even use a cache manager like `SDWebImageCachesManager` to register multiple caches. */ -@protocol SDWebImageCache +@protocol SDImageCache @required /** diff --git a/SDWebImage/SDWebImageCache.m b/SDWebImage/SDImageCacheDefine.m similarity index 98% rename from SDWebImage/SDWebImageCache.m rename to SDWebImage/SDImageCacheDefine.m index bfd67063..d29edc9f 100644 --- a/SDWebImage/SDWebImageCache.m +++ b/SDWebImage/SDImageCacheDefine.m @@ -6,7 +6,7 @@ * file that was distributed with this source code. */ -#import "SDWebImageCache.h" +#import "SDImageCacheDefine.h" #import "SDWebImageCodersManager.h" #import "SDWebImageCoderHelper.h" #import "SDAnimatedImage.h" diff --git a/SDWebImage/SDImageCachesManager.h b/SDWebImage/SDImageCachesManager.h index f6aabb62..08eece9a 100644 --- a/SDWebImage/SDImageCachesManager.h +++ b/SDWebImage/SDImageCachesManager.h @@ -7,7 +7,7 @@ */ #import -#import "SDWebImageCache.h" +#import "SDImageCacheDefine.h" typedef NS_ENUM(NSUInteger, SDImageCachesManagerOperationPolicy) { SDImageCachesManagerOperationPolicySerial, // process all caches serially (from the highest priority to the lowest priority cache by order) @@ -16,7 +16,7 @@ typedef NS_ENUM(NSUInteger, SDImageCachesManagerOperationPolicy) { SDImageCachesManagerOperationPolicyLowestOnly // process the lowest priority cache only }; -@interface SDImageCachesManager : NSObject +@interface SDImageCachesManager : NSObject /** Returns the global shared caches manager instance. @@ -58,20 +58,20 @@ typedef NS_ENUM(NSUInteger, SDImageCachesManagerOperationPolicy) { /** All caches in caches manager. The caches array is a priority queue, which means the later added cache will have the highest priority */ -@property (atomic, copy, readwrite, nullable) NSArray> *caches; +@property (atomic, copy, readwrite, nullable) NSArray> *caches; /** Add a new cache to the end of caches array. Which has the highest priority. @param cache cache */ -- (void)addCache:(nonnull id)cache; +- (void)addCache:(nonnull id)cache; /** Remove a cache in the caches array. @param cache cache */ -- (void)removeCache:(nonnull id)cache; +- (void)removeCache:(nonnull id)cache; @end diff --git a/SDWebImage/SDImageCachesManager.m b/SDWebImage/SDImageCachesManager.m index 2b26f229..111f806c 100644 --- a/SDWebImage/SDImageCachesManager.m +++ b/SDWebImage/SDImageCachesManager.m @@ -95,11 +95,11 @@ #pragma mark - Cache IO operations -- (void)addCache:(id)cache { - if (![cache conformsToProtocol:@protocol(SDWebImageCache)]) { +- (void)addCache:(id)cache { + if (![cache conformsToProtocol:@protocol(SDImageCache)]) { return; } - NSMutableArray> *mutableCaches = [self.caches mutableCopy]; + NSMutableArray> *mutableCaches = [self.caches mutableCopy]; if (!mutableCaches) { mutableCaches = [NSMutableArray array]; } @@ -107,11 +107,11 @@ self.caches = [mutableCaches copy]; } -- (void)removeCache:(id)cache { - if (![cache conformsToProtocol:@protocol(SDWebImageCache)]) { +- (void)removeCache:(id)cache { + if (![cache conformsToProtocol:@protocol(SDImageCache)]) { return; } - NSMutableArray> *mutableCaches = [self.caches mutableCopy]; + NSMutableArray> *mutableCaches = [self.caches mutableCopy]; [mutableCaches removeObject:cache]; self.caches = [mutableCaches copy]; } @@ -122,7 +122,7 @@ if (!key) { return nil; } - NSArray> *caches = [self.caches copy]; + NSArray> *caches = [self.caches copy]; NSUInteger count = caches.count; if (count == 0) { return nil; @@ -131,12 +131,12 @@ } switch (self.queryOperationPolicy) { case SDImageCachesManagerOperationPolicyHighestOnly: { - id cache = caches.lastObject; + id cache = caches.lastObject; return [cache queryImageForKey:key options:options context:context completion:completionBlock]; } break; case SDImageCachesManagerOperationPolicyLowestOnly: { - id cache = caches.firstObject; + id cache = caches.firstObject; return [cache queryImageForKey:key options:options context:context completion:completionBlock]; } break; @@ -164,7 +164,7 @@ if (!key) { return; } - NSArray> *caches = [self.caches copy]; + NSArray> *caches = [self.caches copy]; NSUInteger count = caches.count; if (count == 0) { return; @@ -174,12 +174,12 @@ } switch (self.storeOperationPolicy) { case SDImageCachesManagerOperationPolicyHighestOnly: { - id cache = caches.lastObject; + id cache = caches.lastObject; [cache storeImage:image imageData:imageData forKey:key cacheType:cacheType completion:completionBlock]; } break; case SDImageCachesManagerOperationPolicyLowestOnly: { - id cache = caches.firstObject; + id cache = caches.firstObject; [cache storeImage:image imageData:imageData forKey:key cacheType:cacheType completion:completionBlock]; } break; @@ -202,7 +202,7 @@ if (!key) { return; } - NSArray> *caches = [self.caches copy]; + NSArray> *caches = [self.caches copy]; NSUInteger count = caches.count; if (count == 0) { return; @@ -212,12 +212,12 @@ } switch (self.removeOperationPolicy) { case SDImageCachesManagerOperationPolicyHighestOnly: { - id cache = caches.lastObject; + id cache = caches.lastObject; [cache removeImageForKey:key cacheType:cacheType completion:completionBlock]; } break; case SDImageCachesManagerOperationPolicyLowestOnly: { - id cache = caches.firstObject; + id cache = caches.firstObject; [cache removeImageForKey:key cacheType:cacheType completion:completionBlock]; } break; @@ -240,7 +240,7 @@ if (!key) { return; } - NSArray> *caches = [self.caches copy]; + NSArray> *caches = [self.caches copy]; NSUInteger count = caches.count; if (count == 0) { return; @@ -250,12 +250,12 @@ } switch (self.clearOperationPolicy) { case SDImageCachesManagerOperationPolicyHighestOnly: { - id cache = caches.lastObject; + id cache = caches.lastObject; [cache containsImageForKey:key cacheType:cacheType completion:completionBlock]; } break; case SDImageCachesManagerOperationPolicyLowestOnly: { - id cache = caches.firstObject; + id cache = caches.firstObject; [cache containsImageForKey:key cacheType:cacheType completion:completionBlock]; } break; @@ -277,7 +277,7 @@ } - (void)clearWithCacheType:(SDImageCacheType)cacheType completion:(SDWebImageNoParamsBlock)completionBlock { - NSArray> *caches = [self.caches copy]; + NSArray> *caches = [self.caches copy]; NSUInteger count = caches.count; if (count == 0) { return; @@ -287,12 +287,12 @@ } switch (self.clearOperationPolicy) { case SDImageCachesManagerOperationPolicyHighestOnly: { - id cache = caches.lastObject; + id cache = caches.lastObject; [cache clearWithCacheType:cacheType completion:completionBlock]; } break; case SDImageCachesManagerOperationPolicyLowestOnly: { - id cache = caches.firstObject; + id cache = caches.firstObject; [cache clearWithCacheType:cacheType completion:completionBlock]; } break; @@ -313,10 +313,10 @@ #pragma mark - Concurrent Operation -- (void)concurrentQueryImageForKey:(NSString *)key options:(SDWebImageOptions)options context:(SDWebImageContext *)context completion:(SDImageCacheQueryCompletionBlock)completionBlock enumerator:(NSEnumerator> *)enumerator operation:(SDImageCachesManagerOperation *)operation { +- (void)concurrentQueryImageForKey:(NSString *)key options:(SDWebImageOptions)options context:(SDWebImageContext *)context completion:(SDImageCacheQueryCompletionBlock)completionBlock enumerator:(NSEnumerator> *)enumerator operation:(SDImageCachesManagerOperation *)operation { NSParameterAssert(enumerator); NSParameterAssert(operation); - for (id cache in enumerator) { + for (id cache in enumerator) { [cache queryImageForKey:key options:options context:context completion:^(UIImage * _Nullable image, NSData * _Nullable data, SDImageCacheType cacheType) { if (operation.isCancelled) { // Cancelled @@ -346,10 +346,10 @@ } } -- (void)concurrentStoreImage:(UIImage *)image imageData:(NSData *)imageData forKey:(NSString *)key cacheType:(SDImageCacheType)cacheType completion:(SDWebImageNoParamsBlock)completionBlock enumerator:(NSEnumerator> *)enumerator operation:(SDImageCachesManagerOperation *)operation { +- (void)concurrentStoreImage:(UIImage *)image imageData:(NSData *)imageData forKey:(NSString *)key cacheType:(SDImageCacheType)cacheType completion:(SDWebImageNoParamsBlock)completionBlock enumerator:(NSEnumerator> *)enumerator operation:(SDImageCachesManagerOperation *)operation { NSParameterAssert(enumerator); NSParameterAssert(operation); - for (id cache in enumerator) { + for (id cache in enumerator) { [cache storeImage:image imageData:imageData forKey:key cacheType:cacheType completion:^{ if (operation.isCancelled) { // Cancelled @@ -371,10 +371,10 @@ } } -- (void)concurrentRemoveImageForKey:(NSString *)key cacheType:(SDImageCacheType)cacheType completion:(SDWebImageNoParamsBlock)completionBlock enumerator:(NSEnumerator> *)enumerator operation:(SDImageCachesManagerOperation *)operation { +- (void)concurrentRemoveImageForKey:(NSString *)key cacheType:(SDImageCacheType)cacheType completion:(SDWebImageNoParamsBlock)completionBlock enumerator:(NSEnumerator> *)enumerator operation:(SDImageCachesManagerOperation *)operation { NSParameterAssert(enumerator); NSParameterAssert(operation); - for (id cache in enumerator) { + for (id cache in enumerator) { [cache removeImageForKey:key cacheType:cacheType completion:^{ if (operation.isCancelled) { // Cancelled @@ -396,10 +396,10 @@ } } -- (void)concurrentContainsImageForKey:(NSString *)key cacheType:(SDImageCacheType)cacheType completion:(SDImageCacheContainsCompletionBlock)completionBlock enumerator:(NSEnumerator> *)enumerator operation:(SDImageCachesManagerOperation *)operation { +- (void)concurrentContainsImageForKey:(NSString *)key cacheType:(SDImageCacheType)cacheType completion:(SDImageCacheContainsCompletionBlock)completionBlock enumerator:(NSEnumerator> *)enumerator operation:(SDImageCachesManagerOperation *)operation { NSParameterAssert(enumerator); NSParameterAssert(operation); - for (id cache in enumerator) { + for (id cache in enumerator) { [cache containsImageForKey:key cacheType:cacheType completion:^(SDImageCacheType containsCacheType) { if (operation.isCancelled) { // Cancelled @@ -429,10 +429,10 @@ } } -- (void)concurrentClearWithCacheType:(SDImageCacheType)cacheType completion:(SDWebImageNoParamsBlock)completionBlock enumerator:(NSEnumerator> *)enumerator operation:(SDImageCachesManagerOperation *)operation { +- (void)concurrentClearWithCacheType:(SDImageCacheType)cacheType completion:(SDWebImageNoParamsBlock)completionBlock enumerator:(NSEnumerator> *)enumerator operation:(SDImageCachesManagerOperation *)operation { NSParameterAssert(enumerator); NSParameterAssert(operation); - for (id cache in enumerator) { + for (id cache in enumerator) { [cache clearWithCacheType:cacheType completion:^{ if (operation.isCancelled) { // Cancelled @@ -456,10 +456,10 @@ #pragma mark - Serial Operation -- (void)serialQueryImageForKey:(NSString *)key options:(SDWebImageOptions)options context:(SDWebImageContext *)context completion:(SDImageCacheQueryCompletionBlock)completionBlock enumerator:(NSEnumerator> *)enumerator operation:(SDImageCachesManagerOperation *)operation { +- (void)serialQueryImageForKey:(NSString *)key options:(SDWebImageOptions)options context:(SDWebImageContext *)context completion:(SDImageCacheQueryCompletionBlock)completionBlock enumerator:(NSEnumerator> *)enumerator operation:(SDImageCachesManagerOperation *)operation { NSParameterAssert(enumerator); NSParameterAssert(operation); - id cache = enumerator.nextObject; + id cache = enumerator.nextObject; if (!cache) { // Complete [operation done]; @@ -492,9 +492,9 @@ }]; } -- (void)serialStoreImage:(UIImage *)image imageData:(NSData *)imageData forKey:(NSString *)key cacheType:(SDImageCacheType)cacheType completion:(SDWebImageNoParamsBlock)completionBlock enumerator:(NSEnumerator> *)enumerator { +- (void)serialStoreImage:(UIImage *)image imageData:(NSData *)imageData forKey:(NSString *)key cacheType:(SDImageCacheType)cacheType completion:(SDWebImageNoParamsBlock)completionBlock enumerator:(NSEnumerator> *)enumerator { NSParameterAssert(enumerator); - id cache = enumerator.nextObject; + id cache = enumerator.nextObject; if (!cache) { // Complete if (completionBlock) { @@ -509,9 +509,9 @@ }]; } -- (void)serialRemoveImageForKey:(NSString *)key cacheType:(SDImageCacheType)cacheType completion:(SDWebImageNoParamsBlock)completionBlock enumerator:(NSEnumerator> *)enumerator { +- (void)serialRemoveImageForKey:(NSString *)key cacheType:(SDImageCacheType)cacheType completion:(SDWebImageNoParamsBlock)completionBlock enumerator:(NSEnumerator> *)enumerator { NSParameterAssert(enumerator); - id cache = enumerator.nextObject; + id cache = enumerator.nextObject; if (!cache) { // Complete if (completionBlock) { @@ -526,10 +526,10 @@ }]; } -- (void)serialContainsImageForKey:(NSString *)key cacheType:(SDImageCacheType)cacheType completion:(SDImageCacheContainsCompletionBlock)completionBlock enumerator:(NSEnumerator> *)enumerator operation:(SDImageCachesManagerOperation *)operation { +- (void)serialContainsImageForKey:(NSString *)key cacheType:(SDImageCacheType)cacheType completion:(SDImageCacheContainsCompletionBlock)completionBlock enumerator:(NSEnumerator> *)enumerator operation:(SDImageCachesManagerOperation *)operation { NSParameterAssert(enumerator); NSParameterAssert(operation); - id cache = enumerator.nextObject; + id cache = enumerator.nextObject; if (!cache) { // Complete [operation done]; @@ -562,9 +562,9 @@ }]; } -- (void)serialClearWithCacheType:(SDImageCacheType)cacheType completion:(SDWebImageNoParamsBlock)completionBlock enumerator:(NSEnumerator> *)enumerator { +- (void)serialClearWithCacheType:(SDImageCacheType)cacheType completion:(SDWebImageNoParamsBlock)completionBlock enumerator:(NSEnumerator> *)enumerator { NSParameterAssert(enumerator); - id cache = enumerator.nextObject; + id cache = enumerator.nextObject; if (!cache) { // Complete if (completionBlock) { diff --git a/SDWebImage/SDWebImageManager.h b/SDWebImage/SDWebImageManager.h index 6f338d95..83c5fdd6 100644 --- a/SDWebImage/SDWebImageManager.h +++ b/SDWebImage/SDWebImageManager.h @@ -8,7 +8,7 @@ #import "SDWebImageCompat.h" #import "SDWebImageOperation.h" -#import "SDWebImageCache.h" +#import "SDImageCacheDefine.h" #import "SDWebImageDownloader.h" #import "SDWebImageTransformer.h" #import "SDWebImageCacheKeyFilter.h" @@ -99,7 +99,7 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager]; /** * The image cache used by manager to query image cache. */ -@property (strong, nonatomic, readonly, nonnull) id imageCache; +@property (strong, nonatomic, readonly, nonnull) id imageCache; /** * The image downloader used by manager to download image. @@ -158,7 +158,7 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager]; The default image cache when the manager which is created with no arguments. Such as shared manager or init. Defaults to nil. Means using `SDImageCache.sharedImageCache` */ -@property (nonatomic, class, nullable) id defaultImageCache; +@property (nonatomic, class, nullable) id defaultImageCache; /** The default image downloader for manager which is created with no arguments. Such as shared manager or init. @@ -175,7 +175,7 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager]; * Allows to specify instance of cache and image downloader used with image manager. * @return new instance of `SDWebImageManager` with specified cache and downloader. */ -- (nonnull instancetype)initWithCache:(nonnull id)cache downloader:(nonnull SDWebImageDownloader *)downloader NS_DESIGNATED_INITIALIZER; +- (nonnull instancetype)initWithCache:(nonnull id)cache downloader:(nonnull SDWebImageDownloader *)downloader NS_DESIGNATED_INITIALIZER; /** * Downloads the image at the given URL if not present in cache or return the cached version otherwise. diff --git a/SDWebImage/SDWebImageManager.m b/SDWebImage/SDWebImageManager.m index 84c72340..b7b91bc9 100644 --- a/SDWebImage/SDWebImageManager.m +++ b/SDWebImage/SDWebImageManager.m @@ -13,7 +13,7 @@ #import "SDAnimatedImage.h" #import "SDWebImageError.h" -static id _defaultImageCache; +static id _defaultImageCache; static SDWebImageDownloader *_defaultImageDownloader; @interface SDWebImageCombinedOperation () @@ -36,12 +36,12 @@ static SDWebImageDownloader *_defaultImageDownloader; @implementation SDWebImageManager -+ (id)defaultImageCache { ++ (id)defaultImageCache { return _defaultImageCache; } -+ (void)setDefaultImageCache:(id)defaultImageCache { - if (defaultImageCache && ![defaultImageCache conformsToProtocol:@protocol(SDWebImageCache)]) { ++ (void)setDefaultImageCache:(id)defaultImageCache { + if (defaultImageCache && ![defaultImageCache conformsToProtocol:@protocol(SDImageCache)]) { return; } _defaultImageCache = defaultImageCache; @@ -68,7 +68,7 @@ static SDWebImageDownloader *_defaultImageDownloader; } - (nonnull instancetype)init { - id cache = [[self class] defaultImageCache]; + id cache = [[self class] defaultImageCache]; if (!cache) { cache = [SDImageCache sharedImageCache]; } @@ -79,7 +79,7 @@ static SDWebImageDownloader *_defaultImageDownloader; return [self initWithCache:cache downloader:downloader]; } -- (nonnull instancetype)initWithCache:(nonnull id)cache downloader:(nonnull SDWebImageDownloader *)downloader { +- (nonnull instancetype)initWithCache:(nonnull id)cache downloader:(nonnull SDWebImageDownloader *)downloader { if ((self = [super init])) { _imageCache = cache; _imageDownloader = downloader;