Another clarification: `imageFromDiskCacheForKey:` used to also check the memory cache which I think is misleading. Now `imageFromDiskCacheForKey` only checks the disk cache and the new method `imageFromCacheForKey` checks both caches
This commit is contained in:
parent
df3b6a52eb
commit
ebf40c7ca0
|
@ -144,17 +144,24 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
/**
|
/**
|
||||||
* Query the memory cache synchronously.
|
* Query the memory cache synchronously.
|
||||||
*
|
*
|
||||||
* @param key The unique key used to store the wanted image
|
* @param key The unique key used to store the image
|
||||||
*/
|
*/
|
||||||
- (nullable UIImage *)imageFromMemoryCacheForKey:(nullable NSString *)key;
|
- (nullable UIImage *)imageFromMemoryCacheForKey:(nullable NSString *)key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the disk cache synchronously after checking the memory cache.
|
* Query the disk cache synchronously.
|
||||||
*
|
*
|
||||||
* @param key The unique key used to store the wanted image
|
* @param key The unique key used to store the image
|
||||||
*/
|
*/
|
||||||
- (nullable UIImage *)imageFromDiskCacheForKey:(nullable NSString *)key;
|
- (nullable UIImage *)imageFromDiskCacheForKey:(nullable NSString *)key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query the cache (memory and or disk) synchronously after checking the memory cache.
|
||||||
|
*
|
||||||
|
* @param key The unique key used to store the image
|
||||||
|
*/
|
||||||
|
- (nullable UIImage *)imageFromCacheForKey:(nullable NSString *)key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the image from memory and disk cache asynchronously
|
* Remove the image from memory and disk cache asynchronously
|
||||||
*
|
*
|
||||||
|
|
|
@ -231,7 +231,6 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)diskImageExistsWithKey:(nullable NSString *)key completion:(nullable SDWebImageCheckCacheCompletionBlock)completionBlock {
|
- (void)diskImageExistsWithKey:(nullable NSString *)key completion:(nullable SDWebImageCheckCacheCompletionBlock)completionBlock {
|
||||||
dispatch_async(_ioQueue, ^{
|
dispatch_async(_ioQueue, ^{
|
||||||
BOOL exists = [_fileManager fileExistsAtPath:[self defaultCachePathForKey:key]];
|
BOOL exists = [_fileManager fileExistsAtPath:[self defaultCachePathForKey:key]];
|
||||||
|
@ -255,16 +254,8 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (nullable UIImage *)imageFromDiskCacheForKey:(nullable NSString *)key {
|
- (nullable UIImage *)imageFromDiskCacheForKey:(nullable NSString *)key {
|
||||||
|
|
||||||
// First check the in-memory cache...
|
|
||||||
UIImage *image = [self imageFromMemoryCacheForKey:key];
|
|
||||||
if (image) {
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Second check the disk cache...
|
|
||||||
UIImage *diskImage = [self diskImageForKey:key];
|
UIImage *diskImage = [self diskImageForKey:key];
|
||||||
if (diskImage && self.shouldCacheImagesInMemory) {
|
if (diskImage && self.config.shouldCacheImagesInMemory) {
|
||||||
NSUInteger cost = SDCacheCostForImage(diskImage);
|
NSUInteger cost = SDCacheCostForImage(diskImage);
|
||||||
[self.memCache setObject:diskImage forKey:key cost:cost];
|
[self.memCache setObject:diskImage forKey:key cost:cost];
|
||||||
}
|
}
|
||||||
|
@ -272,6 +263,18 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
return diskImage;
|
return diskImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (nullable UIImage *)imageFromCacheForKey:(nullable NSString *)key {
|
||||||
|
// First check the in-memory cache...
|
||||||
|
UIImage *image = [self imageFromMemoryCacheForKey:key];
|
||||||
|
if (image) {
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second check the disk cache...
|
||||||
|
image = [self imageFromDiskCacheForKey:key];
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
- (nullable NSData *)diskImageDataBySearchingAllPathsForKey:(nullable NSString *)key {
|
- (nullable NSData *)diskImageDataBySearchingAllPathsForKey:(nullable NSString *)key {
|
||||||
NSString *defaultPath = [self defaultCachePathForKey:key];
|
NSString *defaultPath = [self defaultCachePathForKey:key];
|
||||||
NSData *data = [NSData dataWithContentsOfFile:defaultPath];
|
NSData *data = [NSData dataWithContentsOfFile:defaultPath];
|
||||||
|
|
|
@ -118,7 +118,7 @@ static char TAG_ACTIVITY_SHOW;
|
||||||
progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
|
progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
completed:(nullable SDExternalCompletionBlock)completedBlock {
|
completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:url];
|
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:url];
|
||||||
UIImage *lastPreviousCachedImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key];
|
UIImage *lastPreviousCachedImage = [[SDImageCache sharedImageCache] imageFromCacheForKey:key];
|
||||||
|
|
||||||
[self sd_setImageWithURL:url placeholderImage:lastPreviousCachedImage ?: placeholder options:options progress:progressBlock completed:completedBlock];
|
[self sd_setImageWithURL:url placeholderImage:lastPreviousCachedImage ?: placeholder options:options progress:progressBlock completed:completedBlock];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue