diff --git a/CHANGELOG.md b/CHANGELOG.md
index ea9b2ae0..82e062e1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,16 @@
+## [4.3.3 - Cache Serializer, on Mar 12th, 2018](https://github.com/rs/SDWebImage/releases/tag/4.3.3)
+See [all tickets marked for the 4.3.3 release](https://github.com/rs/SDWebImage/milestone/24)
+
+#### Features
+- Manager
+ - Add cacheSerializer to allow user provide modified version of data when storing the disk cache in SDWebImageManager #2245
+ - Add a delegate method to control the custom logic when blocking the failed url #2246
+
+#### Improvements
+- Project
+ - Enable CLANG\_WARN\_OBJC\_IMPLICIT\_RETAIN\_SELF and fix warning #2242
+
+
## [4.3.2 - 4.3 Patch, on Feb 28th, 2018](https://github.com/rs/SDWebImage/releases/tag/4.3.2)
See [all tickets marked for the 4.3.2 release](https://github.com/rs/SDWebImage/milestone/23)
diff --git a/SDWebImage.podspec b/SDWebImage.podspec
index 410a27e9..8f3dd0b8 100644
--- a/SDWebImage.podspec
+++ b/SDWebImage.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SDWebImage'
- s.version = '4.3.2'
+ s.version = '4.3.3'
s.osx.deployment_target = '10.10'
s.ios.deployment_target = '8.0'
diff --git a/SDWebImage/SDWebImageManager.h b/SDWebImage/SDWebImageManager.h
index adb7ab39..222392d0 100644
--- a/SDWebImage/SDWebImageManager.h
+++ b/SDWebImage/SDWebImageManager.h
@@ -122,7 +122,9 @@ typedef void(^SDExternalCompletionBlock)(UIImage * _Nullable image, NSError * _N
typedef void(^SDInternalCompletionBlock)(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL);
-typedef NSString * _Nullable (^SDWebImageCacheKeyFilterBlock)(NSURL * _Nullable url);
+typedef NSString * _Nullable(^SDWebImageCacheKeyFilterBlock)(NSURL * _Nullable url);
+
+typedef NSData * _Nullable(^SDWebImageCacheSerializerBlock)(UIImage * _Nonnull image, NSData * _Nullable data, NSURL * _Nullable imageURL);
@class SDWebImageManager;
@@ -203,15 +205,35 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
*
* @code
-[[SDWebImageManager sharedManager] setCacheKeyFilter:^(NSURL *url) {
+SDWebImageManager.sharedManager.cacheKeyFilter = ^(NSURL * _Nullable url) {
url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path];
return [url absoluteString];
-}];
+};
* @endcode
*/
@property (nonatomic, copy, nullable) SDWebImageCacheKeyFilterBlock cacheKeyFilter;
+/**
+ * The cache serializer is a block used to convert the decoded image, the source downloaded data, to the actual data used for storing to the disk cache. If you return nil, means to generate the data from the image instance, see `SDImageCache`.
+ * For example, if you are using WebP images and facing the slow decoding time issue when later retriving from disk cache again. You can try to encode the decoded image to JPEG/PNG format to disk cache instead of source downloaded data.
+ * @note The `image` arg is nonnull, but when you also provide a image transformer and the image is transformed, the `data` arg may be nil, take attention to this case.
+ * @note This method is called from a global queue in order to not to block the main thread.
+ * @code
+ SDWebImageManager.sharedManager.cacheKeyFilter = ^NSData * _Nullable(UIImage * _Nonnull image, NSData * _Nullable data, NSURL * _Nullable imageURL) {
+ SDImageFormat format = [NSData sd_imageFormatForImageData:data];
+ switch (format) {
+ case SDImageFormatWebP:
+ return image.images ? data : nil;
+ default:
+ return data;
+ }
+ };
+ * @endcode
+ * The default value is nil. Means we just store the source downloaded data to disk cache.
+ */
+@property (nonatomic, copy, nullable) SDWebImageCacheSerializerBlock cacheSerializer;
+
/**
* Returns global shared manager instance.
*/
diff --git a/SDWebImage/SDWebImageManager.m b/SDWebImage/SDWebImageManager.m
index 7f20c380..ff5c4017 100644
--- a/SDWebImage/SDWebImageManager.m
+++ b/SDWebImage/SDWebImageManager.m
@@ -244,15 +244,28 @@
if (transformedImage && finished) {
BOOL imageWasTransformed = ![transformedImage isEqual:downloadedImage];
+ NSData *cacheData;
// pass nil if the image was transformed, so we can recalculate the data from the image
- [self.imageCache storeImage:transformedImage imageData:(imageWasTransformed ? nil : downloadedData) forKey:key toDisk:cacheOnDisk completion:nil];
+ if (self.cacheSerializer) {
+ cacheData = self.cacheSerializer(transformedImage, (imageWasTransformed ? nil : downloadedData), url);
+ } else {
+ cacheData = (imageWasTransformed ? nil : downloadedData);
+ }
+ [self.imageCache storeImage:transformedImage imageData:cacheData forKey:key toDisk:cacheOnDisk completion:nil];
}
[self callCompletionBlockForOperation:strongSubOperation completion:completedBlock image:transformedImage data:downloadedData error:nil cacheType:SDImageCacheTypeNone finished:finished url:url];
});
} else {
if (downloadedImage && finished) {
- [self.imageCache storeImage:downloadedImage imageData:downloadedData forKey:key toDisk:cacheOnDisk completion:nil];
+ if (self.cacheSerializer) {
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
+ NSData *cacheData = self.cacheSerializer(downloadedImage, downloadedData, url);
+ [self.imageCache storeImage:downloadedImage imageData:cacheData forKey:key toDisk:cacheOnDisk completion:nil];
+ });
+ } else {
+ [self.imageCache storeImage:downloadedImage imageData:downloadedData forKey:key toDisk:cacheOnDisk completion:nil];
+ }
}
[self callCompletionBlockForOperation:strongSubOperation completion:completedBlock image:downloadedImage data:downloadedData error:nil cacheType:SDImageCacheTypeNone finished:finished url:url];
}
diff --git a/WebImage/Info.plist b/WebImage/Info.plist
index 96379299..1f3f55d0 100644
--- a/WebImage/Info.plist
+++ b/WebImage/Info.plist
@@ -15,11 +15,11 @@
CFBundlePackageType
FMWK
CFBundleShortVersionString
- 4.3.2
+ 4.3.3
CFBundleSignature
????
CFBundleVersion
- 4.3.2
+ 4.3.3
NSPrincipalClass