mirror of
https://github.com/zhigang1992/PINRemoteImage.git
synced 2026-04-01 09:18:42 +08:00
Use a hashed key when the URL is too long (#189)
* Use a hashed key when the URL is too long * Added tests for new cacheKey behaviour * Conform to project style
This commit is contained in:
committed by
Garrett Moon
parent
05b24714f4
commit
1d04bf82b2
@@ -108,6 +108,11 @@
|
||||
return [NSURL URLWithString:@"https://www.gstatic.com/webp/gallery3/4_webp_ll.webp"];
|
||||
}
|
||||
|
||||
- (NSURL *)veryLongURL
|
||||
{
|
||||
return [NSURL URLWithString:@"https://placekitten.com/g/200/300?longarg=helloMomHowAreYouDoing.IamFineJustMovedToLiveWithANiceChapWeTravelTogetherInHisBlueBoxThroughSpaceAndTimeMaybeYouveMetHimAlready.YesterdayWeMetACultureOfPeopleWithTentaclesWhoSingWithAVeryCelestialVoice.SoGood.SeeYouSoon.MaybeYesterday.WhoKnows.XOXO"];
|
||||
}
|
||||
|
||||
#pragma mark - <PINURLSessionManagerDelegate>
|
||||
|
||||
- (void)didReceiveData:(NSData *)data forTask:(NSURLSessionTask *)task
|
||||
@@ -763,4 +768,43 @@
|
||||
[self waitForExpectationsWithTimeout:[self timeoutTimeInterval] handler:nil];
|
||||
}
|
||||
|
||||
- (void)testDiskCacheOnLongURLs
|
||||
{
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Image is available in the disk cache"];
|
||||
PINCache *cache = self.imageManager.cache;
|
||||
NSURL *longURL = [self veryLongURL];
|
||||
NSString *key = [self.imageManager cacheKeyForURL:longURL processorKey:nil];
|
||||
[self.imageManager downloadImageWithURL:longURL
|
||||
options:PINRemoteImageManagerDownloadOptionsNone
|
||||
completion:^(PINRemoteImageManagerResult *result)
|
||||
{
|
||||
XCTAssertNotNil(result.image, @"Image should not be nil");
|
||||
id diskCachedObj = [cache.diskCache objectForKey:key];
|
||||
XCTAssertNotNil(diskCachedObj);
|
||||
[expectation fulfill];
|
||||
}];
|
||||
|
||||
[self waitForExpectationsWithTimeout:[self timeoutTimeInterval] handler:nil];
|
||||
}
|
||||
|
||||
- (void)testLongCacheKeyCreationPerformance
|
||||
{
|
||||
[self measureBlock:^{
|
||||
NSURL *longURL = [self veryLongURL];
|
||||
for (NSUInteger i = 0; i < 10000; i++) {
|
||||
__unused NSString *key = [self.imageManager cacheKeyForURL:longURL processorKey:nil];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testDefaultCacheKeyCreationPerformance
|
||||
{
|
||||
[self measureBlock:^{
|
||||
NSURL *defaultURL = [self JPEGURL];
|
||||
for (NSUInteger i = 0; i < 10000; i++) {
|
||||
__unused NSString *key = [self.imageManager cacheKeyForURL:defaultURL processorKey:nil];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user