diff --git a/SDWebImage/SDWebImageDownloader.m b/SDWebImage/SDWebImageDownloader.m index 1dbe85a31..8e776fd08 100644 --- a/SDWebImage/SDWebImageDownloader.m +++ b/SDWebImage/SDWebImageDownloader.m @@ -119,7 +119,7 @@ - (NSInteger)maxConcurrentDownloads [self addProgressCallback:progressBlock andCompletedBlock:completedBlock forURL:url createCallback:^ { - // In order to prevent from potential duplicate caching (NSURLCache + SDImageCache) we disable the cache for image requests + // In order to prevent from potential duplicate caching (NSURLCache + SDImageCache) we disable the cache for image requests if told otherwise NSMutableURLRequest *request = [NSMutableURLRequest.alloc initWithURL:url cachePolicy:(options & SDWebImageDownloaderEnableNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:15]; request.HTTPShouldHandleCookies = NO; request.HTTPShouldUsePipelining = YES; diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index 1dbc069be..cbe45d846 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -311,8 +311,15 @@ - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)err - (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse { - // Prevents caching of responses - return nil; + if (self.request.cachePolicy == NSURLRequestReloadIgnoringLocalCacheData) + { + // Prevents caching of responses + return nil; + } + else + { + return cachedResponse; + } }