Fix NSURLResponse not cached when `SDWebImageDownloaderEnableNSURLCache` is passed #326

This commit is contained in:
Olivier Poitrey 2013-03-12 14:29:47 +01:00
parent 5cd7c0db46
commit f097ef7558
2 changed files with 10 additions and 3 deletions

View File

@ -119,7 +119,7 @@ static NSString *const kCompletedCallbackKey = @"completed";
[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;

View File

@ -311,8 +311,15 @@
- (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;
}
}