Skip to content

Commit f097ef7

Browse files
author
Olivier Poitrey
committed
Fix NSURLResponse not cached when SDWebImageDownloaderEnableNSURLCache is passed SDWebImage#326
1 parent 5cd7c0d commit f097ef7

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

SDWebImage/SDWebImageDownloader.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ - (NSInteger)maxConcurrentDownloads
119119

120120
[self addProgressCallback:progressBlock andCompletedBlock:completedBlock forURL:url createCallback:^
121121
{
122-
// In order to prevent from potential duplicate caching (NSURLCache + SDImageCache) we disable the cache for image requests
122+
// In order to prevent from potential duplicate caching (NSURLCache + SDImageCache) we disable the cache for image requests if told otherwise
123123
NSMutableURLRequest *request = [NSMutableURLRequest.alloc initWithURL:url cachePolicy:(options & SDWebImageDownloaderEnableNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:15];
124124
request.HTTPShouldHandleCookies = NO;
125125
request.HTTPShouldUsePipelining = YES;

SDWebImage/SDWebImageDownloaderOperation.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,15 @@ - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)err
311311

312312
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse
313313
{
314-
// Prevents caching of responses
315-
return nil;
314+
if (self.request.cachePolicy == NSURLRequestReloadIgnoringLocalCacheData)
315+
{
316+
// Prevents caching of responses
317+
return nil;
318+
}
319+
else
320+
{
321+
return cachedResponse;
322+
}
316323
}
317324

318325

0 commit comments

Comments
 (0)