Allow user to provide reading options such as mapped file to improve performance in SDImageCache disk cache
This commit is contained in:
parent
c1df782869
commit
e1603e1800
|
@ -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<NSString *> *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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue