Permalink
Browse files

Fix NSURLResponse not cached when `SDWebImageDownloaderEnableNSURLCac…

…he` is passed #326
  • Loading branch information...
1 parent 5cd7c0d commit f097ef7558f46617a4fffe3a67134b6da16c3054 @rs committed Mar 12, 2013
Showing with 10 additions and 3 deletions.
  1. +1 −1 SDWebImage/SDWebImageDownloader.m
  2. +9 −2 SDWebImage/SDWebImageDownloaderOperation.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;
@@ -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;
+ }
}

0 comments on commit f097ef7

Please sign in to comment.