Skip to content

Commit

Permalink
Fix NSURLResponse not cached when `SDWebImageDownloaderEnableNSURLCac…
Browse files Browse the repository at this point in the history
…he` is passed SDWebImage#326
  • Loading branch information
Olivier Poitrey authored and Jack Tihon committed Mar 12, 2013
1 parent 2e44b5b commit 6848cfa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion SDWebImage/SDWebImageDownloader.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions SDWebImage/SDWebImageDownloaderOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}


Expand Down

0 comments on commit 6848cfa

Please sign in to comment.