Merge pull request #3104 from kinarobin/fix-memory-cache
Fix store cache in memory bug
This commit is contained in:
commit
d31e82fdd1
|
@ -532,11 +532,18 @@ static NSString * _defaultDiskCacheDirectory;
|
|||
// the image is from in-memory cache, but need image data
|
||||
diskImage = image;
|
||||
} else if (diskData) {
|
||||
// decode image data only if in-memory cache missed
|
||||
diskImage = [self diskImageForKey:key data:diskData options:options context:context];
|
||||
if (diskImage && self.config.shouldCacheImagesInMemory) {
|
||||
NSUInteger cost = diskImage.sd_memoryCost;
|
||||
[self.memoryCache setObject:diskImage forKey:key cost:cost];
|
||||
BOOL shouldCacheToMomery = YES;
|
||||
if (context[SDWebImageContextStoreCacheType]) {
|
||||
SDImageCacheType cacheType = [context[SDWebImageContextStoreCacheType] integerValue];
|
||||
shouldCacheToMomery = (cacheType == SDImageCacheTypeAll || cacheType == SDImageCacheTypeMemory);
|
||||
}
|
||||
if (shouldCacheToMomery) {
|
||||
// decode image data only if in-memory cache missed
|
||||
diskImage = [self diskImageForKey:key data:diskData options:options context:context];
|
||||
if (diskImage && self.config.shouldCacheImagesInMemory) {
|
||||
NSUInteger cost = diskImage.sd_memoryCost;
|
||||
[self.memoryCache setObject:diskImage forKey:key cost:cost];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -626,6 +626,18 @@ static NSString *kTestImageKeyPNG = @"TestImageKey.png";
|
|||
}
|
||||
|
||||
#pragma mark - SDImageCache & SDImageCachesManager
|
||||
- (void)test49SDImageCacheQueryOp {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"SDImageCache query op works"];
|
||||
NSData *data = [[SDImageCodersManager sharedManager] encodedDataWithImage:[self testJPEGImage] format:SDImageFormatJPEG options:nil];
|
||||
[[SDImageCache sharedImageCache] storeImageDataToDisk:data forKey:kTestImageKeyJPEG];
|
||||
|
||||
[[SDImageCachesManager sharedManager] queryImageForKey:kTestImageKeyJPEG options:0 context:@{SDWebImageContextStoreCacheType : @(SDImageCacheTypeDisk)} cacheType:SDImageCacheTypeAll completion:^(UIImage * _Nullable image, NSData * _Nullable data, SDImageCacheType cacheType) {
|
||||
expect([[SDImageCache sharedImageCache] imageFromMemoryCacheForKey:kTestImageKeyJPEG]).beNil();
|
||||
[expectation fulfill];
|
||||
}];
|
||||
[self waitForExpectationsWithCommonTimeout];
|
||||
}
|
||||
|
||||
- (void)test50SDImageCacheQueryOp {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"SDImageCache query op works"];
|
||||
[[SDImageCache sharedImageCache] storeImage:[self testJPEGImage] forKey:kTestImageKeyJPEG toDisk:NO completion:nil];
|
||||
|
|
Loading…
Reference in New Issue