diff --git a/SDWebImage/SDImageCache.m b/SDWebImage/SDImageCache.m index 813cec63..dbbc21c6 100644 --- a/SDWebImage/SDImageCache.m +++ b/SDWebImage/SDImageCache.m @@ -311,14 +311,14 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { - (nullable NSData *)diskImageDataBySearchingAllPathsForKey:(nullable NSString *)key { NSString *defaultPath = [self defaultCachePathForKey:key]; - NSData *data = [NSData dataWithContentsOfFile:defaultPath]; + NSData *data = [NSData dataWithContentsOfFile:defaultPath options:self.config.diskCacheReadingOptions error:nil]; if (data) { return data; } // fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name // checking the key with and without the extension - data = [NSData dataWithContentsOfFile:defaultPath.stringByDeletingPathExtension]; + data = [NSData dataWithContentsOfFile:defaultPath.stringByDeletingPathExtension options:self.config.diskCacheReadingOptions error:nil]; if (data) { return data; } @@ -326,14 +326,14 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { NSArray *customPaths = [self.customPaths copy]; for (NSString *path in customPaths) { NSString *filePath = [self cachePathForKey:key inPath:path]; - NSData *imageData = [NSData dataWithContentsOfFile:filePath]; + NSData *imageData = [NSData dataWithContentsOfFile:filePath options:self.config.diskCacheReadingOptions error:nil]; if (imageData) { return imageData; } // fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name // checking the key with and without the extension - imageData = [NSData dataWithContentsOfFile:filePath.stringByDeletingPathExtension]; + imageData = [NSData dataWithContentsOfFile:filePath.stringByDeletingPathExtension options:self.config.diskCacheReadingOptions error:nil]; if (imageData) { return imageData; } diff --git a/SDWebImage/SDImageCacheConfig.h b/SDWebImage/SDImageCacheConfig.h index b1523e29..20f2d108 100644 --- a/SDWebImage/SDImageCacheConfig.h +++ b/SDWebImage/SDImageCacheConfig.h @@ -18,7 +18,7 @@ @property (assign, nonatomic) BOOL shouldDecompressImages; /** - * disable iCloud backup [defaults to YES] + * disable iCloud backup [defaults to YES] */ @property (assign, nonatomic) BOOL shouldDisableiCloud; @@ -28,7 +28,13 @@ @property (assign, nonatomic) BOOL shouldCacheImagesInMemory; /** - * The maximum length of time to keep an image in the cache, in seconds + * The reading options while reading cache from disk. + * Defaults to 0. You can set this to mapped file to improve performance. + */ +@property (assign, nonatomic) NSDataReadingOptions diskCacheReadingOptions; + +/** + * The maximum length of time to keep an image in the cache, in seconds. */ @property (assign, nonatomic) NSInteger maxCacheAge;