Merge pull request #1994 from bpoplauschi/fix_request_cache_policy

Fix request cache policy
This commit is contained in:
DreamPiggy 2017-09-21 10:42:24 +08:00 committed by GitHub
commit 446c33f14f
2 changed files with 11 additions and 15 deletions

View File

@ -43,11 +43,13 @@
placeholderImage:nil placeholderImage:nil
options:SDWebImageProgressiveDownload options:SDWebImageProgressiveDownload
progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL *targetURL) { progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL *targetURL) {
if (!activityIndicator) { dispatch_async(dispatch_get_main_queue(), ^{
[weakImageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]]; if (!activityIndicator) {
activityIndicator.center = weakImageView.center; [weakImageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];
[activityIndicator startAnimating]; activityIndicator.center = weakImageView.center;
} [activityIndicator startAnimating];
}
});
} }
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
[activityIndicator removeFromSuperview]; [activityIndicator removeFromSuperview];

View File

@ -166,16 +166,10 @@
} }
// In order to prevent from potential duplicate caching (NSURLCache + SDImageCache) we disable the cache for image requests if told otherwise // In order to prevent from potential duplicate caching (NSURLCache + SDImageCache) we disable the cache for image requests if told otherwise
NSURLRequestCachePolicy cachePolicy = NSURLRequestReloadIgnoringLocalCacheData; NSURLRequestCachePolicy cachePolicy = options & SDWebImageDownloaderUseNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData;
if (options & SDWebImageDownloaderUseNSURLCache) { NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url
if (options & SDWebImageDownloaderIgnoreCachedResponse) { cachePolicy:cachePolicy
cachePolicy = NSURLRequestReturnCacheDataDontLoad; timeoutInterval:timeoutInterval];
} else {
cachePolicy = NSURLRequestUseProtocolCachePolicy;
}
}
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:cachePolicy timeoutInterval:timeoutInterval];
request.HTTPShouldHandleCookies = (options & SDWebImageDownloaderHandleCookies); request.HTTPShouldHandleCookies = (options & SDWebImageDownloaderHandleCookies);
request.HTTPShouldUsePipelining = YES; request.HTTPShouldUsePipelining = YES;