mirror of
https://github.com/SDWebImage/SDWebImage.git
synced 2026-04-07 19:27:40 +00:00
fix store cache in memory bug
This commit is contained in:
@@ -523,11 +523,19 @@
|
||||
cacheType = SDImageCacheTypeMemory;
|
||||
} else if (diskData) {
|
||||
cacheType = SDImageCacheTypeDisk;
|
||||
// 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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -607,6 +607,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];
|
||||
|
||||
Reference in New Issue
Block a user