Rename the the extended data to bind it into the UIImage object, which make it compatible for memory cache

This commit is contained in:
DreamPiggy 2019-11-24 01:33:08 +08:00
parent 892a7ad892
commit 7c8d3225c8
5 changed files with 29 additions and 27 deletions

View File

@ -91,10 +91,10 @@
325C46292233A0A8004CAE11 /* NSBezierPath+RoundedCorners.m in Sources */ = {isa = PBXBuildFile; fileRef = 325C46252233A0A8004CAE11 /* NSBezierPath+RoundedCorners.m */; };
325F7CC623893B2E00AEDFCC /* NSFileManager+ExtendedAttributes.h in Headers */ = {isa = PBXBuildFile; fileRef = 325F7CC423893B2E00AEDFCC /* NSFileManager+ExtendedAttributes.h */; settings = {ATTRIBUTES = (Private, ); }; };
325F7CC723893B2E00AEDFCC /* NSFileManager+ExtendedAttributes.m in Sources */ = {isa = PBXBuildFile; fileRef = 325F7CC523893B2E00AEDFCC /* NSFileManager+ExtendedAttributes.m */; };
325F7CCA238942AB00AEDFCC /* NSData+ExtendedData.h in Headers */ = {isa = PBXBuildFile; fileRef = 325F7CC8238942AB00AEDFCC /* NSData+ExtendedData.h */; settings = {ATTRIBUTES = (Public, ); }; };
325F7CCB238942AB00AEDFCC /* NSData+ExtendedData.m in Sources */ = {isa = PBXBuildFile; fileRef = 325F7CC9238942AB00AEDFCC /* NSData+ExtendedData.m */; };
325F7CCC2389463D00AEDFCC /* NSData+ExtendedData.m in Sources */ = {isa = PBXBuildFile; fileRef = 325F7CC9238942AB00AEDFCC /* NSData+ExtendedData.m */; };
325F7CCD2389467800AEDFCC /* NSData+ExtendedData.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 325F7CC8238942AB00AEDFCC /* NSData+ExtendedData.h */; };
325F7CCA238942AB00AEDFCC /* UIImage+ExtendedData.h in Headers */ = {isa = PBXBuildFile; fileRef = 325F7CC8238942AB00AEDFCC /* UIImage+ExtendedData.h */; settings = {ATTRIBUTES = (Public, ); }; };
325F7CCB238942AB00AEDFCC /* UIImage+ExtendedData.m in Sources */ = {isa = PBXBuildFile; fileRef = 325F7CC9238942AB00AEDFCC /* UIImage+ExtendedData.m */; };
325F7CCC2389463D00AEDFCC /* UIImage+ExtendedData.m in Sources */ = {isa = PBXBuildFile; fileRef = 325F7CC9238942AB00AEDFCC /* UIImage+ExtendedData.m */; };
325F7CCD2389467800AEDFCC /* UIImage+ExtendedData.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 325F7CC8238942AB00AEDFCC /* UIImage+ExtendedData.h */; };
326E2F2E236F0B23006F847F /* SDAnimatedImagePlayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 326E2F2C236F0B23006F847F /* SDAnimatedImagePlayer.h */; settings = {ATTRIBUTES = (Public, ); }; };
326E2F2F236F0B23006F847F /* SDAnimatedImagePlayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 326E2F2D236F0B23006F847F /* SDAnimatedImagePlayer.m */; };
326E2F30236F0B23006F847F /* SDAnimatedImagePlayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 326E2F2D236F0B23006F847F /* SDAnimatedImagePlayer.m */; };
@ -304,7 +304,7 @@
dstPath = include/SDWebImage;
dstSubfolderSpec = 16;
files = (
325F7CCD2389467800AEDFCC /* NSData+ExtendedData.h in Copy Headers */,
325F7CCD2389467800AEDFCC /* UIImage+ExtendedData.h in Copy Headers */,
326E2F36236F1E30006F847F /* SDAnimatedImagePlayer.h in Copy Headers */,
3250C9F12355E3DF0093A896 /* SDWebImageDownloaderDecryptor.h in Copy Headers */,
325427662355783C0042BAA4 /* SDWebImageDownloaderResponseModifier.h in Copy Headers */,
@ -416,8 +416,8 @@
325C46252233A0A8004CAE11 /* NSBezierPath+RoundedCorners.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSBezierPath+RoundedCorners.m"; sourceTree = "<group>"; };
325F7CC423893B2E00AEDFCC /* NSFileManager+ExtendedAttributes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSFileManager+ExtendedAttributes.h"; sourceTree = "<group>"; };
325F7CC523893B2E00AEDFCC /* NSFileManager+ExtendedAttributes.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSFileManager+ExtendedAttributes.m"; sourceTree = "<group>"; };
325F7CC8238942AB00AEDFCC /* NSData+ExtendedData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "NSData+ExtendedData.h"; path = "Core/NSData+ExtendedData.h"; sourceTree = "<group>"; };
325F7CC9238942AB00AEDFCC /* NSData+ExtendedData.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "NSData+ExtendedData.m"; path = "Core/NSData+ExtendedData.m"; sourceTree = "<group>"; };
325F7CC8238942AB00AEDFCC /* UIImage+ExtendedData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "UIImage+ExtendedData.h"; path = "Core/UIImage+ExtendedData.h"; sourceTree = "<group>"; };
325F7CC9238942AB00AEDFCC /* UIImage+ExtendedData.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "UIImage+ExtendedData.m"; path = "Core/UIImage+ExtendedData.m"; sourceTree = "<group>"; };
326E2F2C236F0B23006F847F /* SDAnimatedImagePlayer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SDAnimatedImagePlayer.h; path = Core/SDAnimatedImagePlayer.h; sourceTree = "<group>"; };
326E2F2D236F0B23006F847F /* SDAnimatedImagePlayer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SDAnimatedImagePlayer.m; path = Core/SDAnimatedImagePlayer.m; sourceTree = "<group>"; };
326E2F31236F1D58006F847F /* SDDeviceHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDDeviceHelper.h; sourceTree = "<group>"; };
@ -757,8 +757,8 @@
children = (
5D5B9140188EE8DD006D06BD /* NSData+ImageContentType.h */,
5D5B9141188EE8DD006D06BD /* NSData+ImageContentType.m */,
325F7CC8238942AB00AEDFCC /* NSData+ExtendedData.h */,
325F7CC9238942AB00AEDFCC /* NSData+ExtendedData.m */,
325F7CC8238942AB00AEDFCC /* UIImage+ExtendedData.h */,
325F7CC9238942AB00AEDFCC /* UIImage+ExtendedData.m */,
A18A6CC5172DC28500419892 /* UIImage+GIF.h */,
A18A6CC6172DC28500419892 /* UIImage+GIF.m */,
329A18571FFF5DFD008C9A2F /* UIImage+Metadata.h */,
@ -864,7 +864,7 @@
3257EAFA21898AED0097B271 /* SDImageGraphics.h in Headers */,
32D3CDD121DDE87300C4DB49 /* UIImage+MemoryCacheCost.h in Headers */,
328BB6AC2081FEE500760D6C /* SDWebImageCacheSerializer.h in Headers */,
325F7CCA238942AB00AEDFCC /* NSData+ExtendedData.h in Headers */,
325F7CCA238942AB00AEDFCC /* UIImage+ExtendedData.h in Headers */,
325C46272233A0A8004CAE11 /* NSBezierPath+RoundedCorners.h in Headers */,
321B378F2083290E00C0EA77 /* SDImageLoadersManager.h in Headers */,
329A185B1FFF5DFD008C9A2F /* UIImage+Metadata.h in Headers */,
@ -1115,7 +1115,7 @@
3257EAFD21898AED0097B271 /* SDImageGraphics.m in Sources */,
3290FA0C1FA478AF0047D20C /* SDImageFrame.m in Sources */,
325C46232233A02E004CAE11 /* UIColor+HexString.m in Sources */,
325F7CCB238942AB00AEDFCC /* NSData+ExtendedData.m in Sources */,
325F7CCB238942AB00AEDFCC /* UIImage+ExtendedData.m in Sources */,
321E60C61F38E91700405457 /* UIImage+ForceDecode.m in Sources */,
3244062E2296C5F400A36084 /* SDWebImageOptionsProcessor.m in Sources */,
3250C9F02355D9DA0093A896 /* SDWebImageDownloaderDecryptor.m in Sources */,
@ -1217,7 +1217,7 @@
5376130D155AD0D5005750A4 /* SDWebImagePrefetcher.m in Sources */,
328BB6C72082581100760D6C /* SDDiskCache.m in Sources */,
3248475D201775F600AF9E5A /* SDAnimatedImageView.m in Sources */,
325F7CCC2389463D00AEDFCC /* NSData+ExtendedData.m in Sources */,
325F7CCC2389463D00AEDFCC /* UIImage+ExtendedData.m in Sources */,
32D1222A2080B2EB003685A3 /* SDImageCachesManager.m in Sources */,
32B9B53D206ED4230026769D /* SDWebImageDownloaderConfig.m in Sources */,
43A9186B1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */,

View File

@ -14,7 +14,7 @@
#import "SDAnimatedImage.h"
#import "UIImage+MemoryCacheCost.h"
#import "UIImage+Metadata.h"
#import "NSData+ExtendedData.h"
#import "UIImage+ExtendedData.h"
@interface SDImageCache ()
@ -198,6 +198,13 @@
data = [[SDImageCodersManager sharedManager] encodedDataWithImage:image format:format options:nil];
}
[self _storeImageDataToDisk:data forKey:key];
if (image) {
// Check extended data
NSData *extendedData = image.sd_extendedData;
if (extendedData) {
[self.diskCache setExtendedData:extendedData forKey:key];
}
}
}
if (completionBlock) {
@ -239,10 +246,6 @@
}
[self.diskCache setData:imageData forKey:key];
NSData *extendedData = imageData.sd_extendedData;
if (extendedData) {
[self.diskCache setExtendedData:extendedData forKey:key];
}
}
#pragma mark - Query and Retrieve Ops
@ -325,11 +328,6 @@
NSData *data = [self.diskCache dataForKey:key];
if (data) {
// Check extended data
NSData *extendedData = [self.diskCache extendedDataForKey:key];
if (extendedData) {
data.sd_extendedData = extendedData;
}
return data;
}
@ -356,6 +354,10 @@
- (nullable UIImage *)diskImageForKey:(nullable NSString *)key data:(nullable NSData *)data options:(SDImageCacheOptions)options context:(SDWebImageContext *)context {
if (data) {
UIImage *image = SDImageCacheDecodeImageData(data, key, [[self class] imageOptionsFromCacheOptions:options], context);
if (image) {
// Check extended data
image.sd_extendedData = [self.diskCache extendedDataForKey:key];
}
return image;
} else {
return nil;

View File

@ -10,10 +10,10 @@
#import <Foundation/Foundation.h>
#import "SDWebImageCompat.h"
@interface NSData (ExtendedData)
@interface UIImage (ExtendedData)
/**
Read and Write the extended data to the image data. Which can hold some extra metadata like Image's scale factor, URL rich link, date, etc.
Read and Write the extended data and bind it to the image. Which can hold some extra metadata like Image's scale factor, URL rich link, date, etc.
The extended data will be write to disk cache as well as the image data. The disk cache preserve both of the data and extended data with the same cache key.
*/
@property (nonatomic, strong, nullable) NSData *sd_extendedData;

View File

@ -7,10 +7,10 @@
* file that was distributed with this source code.
*/
#import "NSData+ExtendedData.h"
#import "UIImage+ExtendedData.h"
#import <objc/runtime.h>
@implementation NSData (ExtendedData)
@implementation UIImage (ExtendedData)
- (NSData *)sd_extendedData {
return objc_getAssociatedObject(self, @selector(sd_extendedData));

View File

@ -46,6 +46,7 @@ FOUNDATION_EXPORT const unsigned char WebImageVersionString[];
#import <SDWebImage/UIImage+Metadata.h>
#import <SDWebImage/UIImage+MultiFormat.h>
#import <SDWebImage/UIImage+MemoryCacheCost.h>
#import <SDWebImage/UIImage+ExtendedData.h>
#import <SDWebImage/SDWebImageOperation.h>
#import <SDWebImage/SDWebImageDownloader.h>
#import <SDWebImage/SDWebImageTransition.h>
@ -67,7 +68,6 @@ FOUNDATION_EXPORT const unsigned char WebImageVersionString[];
#import <SDWebImage/UIImage+GIF.h>
#import <SDWebImage/UIImage+ForceDecode.h>
#import <SDWebImage/NSData+ImageContentType.h>
#import <SDWebImage/NSData+ExtendedData.h>
#import <SDWebImage/SDWebImageDefine.h>
#import <SDWebImage/SDWebImageError.h>
#import <SDWebImage/SDWebImageOptionsProcessor.h>