Improvement for #1608 and #1623 should solve the issue for most of the cases. Apparently there is a race condition on NSURLCache and we avoid making those checks unless necesarry (basically we will query the NSURLCache only when `SDWebImageRefreshCached` is used and the image cannot be cached by the system when it's too big or behind authentication)

This commit is contained in:
Bogdan Poplauschi 2016-09-05 19:53:39 +03:00
parent dea7b4594d
commit e7bd5ab0fa
1 changed files with 7 additions and 5 deletions

View File

@ -404,12 +404,14 @@ didReceiveResponse:(NSURLResponse *)response
} else {
SDWebImageDownloaderCompletedBlock completionBlock = self.completedBlock;
if (![[NSURLCache sharedURLCache] cachedResponseForRequest:self.request]) {
responseFromCached = NO;
}
if (completionBlock) {
if (self.options & SDWebImageDownloaderIgnoreCachedResponse && responseFromCached) {
/**
* See #1608 and #1623 - apparently, there is a race condition on `NSURLCache` that causes a crash
* Limited the calls to `cachedResponseForRequest:` only for cases where we should ignore the cached response
* and images for which responseFromCached is YES (only the ones that cannot be cached).
* Note: responseFromCached is set to NO inside `willCacheResponse:`. This method doesn't get called for large images or images behind authentication
*/
if (self.options & SDWebImageDownloaderIgnoreCachedResponse && responseFromCached && [[NSURLCache sharedURLCache] cachedResponseForRequest:self.request]) {
completionBlock(nil, nil, nil, YES);
} else if (self.imageData) {
UIImage *image = [UIImage sd_imageWithData:self.imageData];