Added the query cache type cases as well, update some documentation
This commit is contained in:
parent
067174b1fd
commit
ce4eced4d4
|
@ -260,7 +260,7 @@ FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextImageP
|
|||
FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextImageThumbnailPixelSize;
|
||||
|
||||
/**
|
||||
A SDImageCacheType raw value which specify the source of cache to query. For example, you can query memory only, query disk only, or query from both memory and disk cache.
|
||||
A SDImageCacheType raw value which specify the source of cache to query. Specify `SDImageCacheTypeDisk` to query from disk cache only; `SDImageCacheTypeMemory` to query from memory only. And `SDImageCacheTypeAll` to query from both memory cache and disk cache. Specify `SDImageCacheTypeNone` is invalid and totally ignore the cache query.
|
||||
If not provide or the value is invalid, we will use `SDImageCacheTypeAll`. (NSNumber)
|
||||
*/
|
||||
FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextQueryCacheType;
|
||||
|
|
|
@ -294,6 +294,29 @@
|
|||
[self waitForExpectationsWithCommonTimeout];
|
||||
}
|
||||
|
||||
- (void)test15ThatQueryCacheTypeWork {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Image query cache type works"];
|
||||
NSURL *url = [NSURL URLWithString:@"http://via.placeholder.com/101x101.png"];
|
||||
NSString *key = [SDWebImageManager.sharedManager cacheKeyForURL:url];
|
||||
NSData *testImageData = [NSData dataWithContentsOfFile:[self testJPEGPath]];
|
||||
[SDImageCache.sharedImageCache storeImageDataToDisk:testImageData forKey:key];
|
||||
|
||||
// Query memory first
|
||||
[SDWebImageManager.sharedManager loadImageWithURL:url options:SDWebImageFromCacheOnly context:@{SDWebImageContextQueryCacheType : @(SDImageCacheTypeMemory)} progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
|
||||
expect(image).beNil();
|
||||
expect(cacheType).equal(SDImageCacheTypeNone);
|
||||
// Query disk secondly
|
||||
[SDWebImageManager.sharedManager loadImageWithURL:url options:SDWebImageFromCacheOnly context:@{SDWebImageContextQueryCacheType : @(SDImageCacheTypeDisk)} progress:nil completed:^(UIImage * _Nullable image2, NSData * _Nullable data2, NSError * _Nullable error2, SDImageCacheType cacheType2, BOOL finished2, NSURL * _Nullable imageURL2) {
|
||||
expect(image2).notTo.beNil();
|
||||
expect(cacheType2).equal(SDImageCacheTypeDisk);
|
||||
[SDImageCache.sharedImageCache removeImageFromDiskForKey:key];
|
||||
[expectation fulfill];
|
||||
}];
|
||||
}];
|
||||
|
||||
[self waitForExpectationsWithCommonTimeout];
|
||||
}
|
||||
|
||||
- (NSString *)testJPEGPath {
|
||||
NSBundle *testBundle = [NSBundle bundleForClass:[self class]];
|
||||
return [testBundle pathForResource:@"TestImage" ofType:@"jpg"];
|
||||
|
|
|
@ -188,6 +188,7 @@ static NSString * const SDWebImageTestDiskCacheExtendedAttributeName = @"com.hac
|
|||
} else if ([self.diskCache containsDataForKey:key]) {
|
||||
containsCacheType = SDImageCacheTypeDisk;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue