SDWebImage: Load image with option `SDWebImageRefreshCached` get error

Issue Info

Info Value
Platform Name ios
Platform Version all
SDWebImage Version 4.1.0
Integration Method cocoapods
Xcode Version Xcode 8.3
Repro rate all the time (100%)
Repro with our demo prj Yes, just add little code.
Demo project link none

Issue Description and Steps

Replace this line as the link below with code options:SDWebImageProgressiveDownload | SDWebImageRefreshCached, and run the demo. When first navigate to the detail view of an image, it will show as expect, but go back and do it again, no image show now.

https://github.com/rs/SDWebImage/blob/master/Examples/SDWebImage Demo/DetailViewController.m#L44

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 22 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Reproduced. +1

I have move to using kingfisher,which has a good code quality

@bpoplauschi Sorry to bother because I do not use that SDWebImageDownloaderIgnoreCachedResponse options in my iOS application. After I check the commit history but still do not understand what’s this option means. If I choose to use NSURLCache instead of SDImageCache, I means to set NSURLRequestUseProtocolCachePolicy right ? But this option seems to set back that NSURLRequestReloadIgnoringLocalCacheData. It’s this really useful ?(You can just do not set any and this is the default behavior). Or may this means the description Call completion block with nil image/imageData if the image was read from NSURLCache

So maybe the code below can specify that behavior(but I think it’s really strange and please do not use this if I’m something wrong):

// In order to prevent from potential duplicate caching (NSURLCache + SDImageCache) we disable the cache for image requests if told otherwise
NSURLRequestCachePolicy cachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
if (options & SDWebImageDownloaderUseNSURLCache) {
    cachePolicy = NSURLRequestUseProtocolCachePolicy;
}

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:cachePolicy timeoutInterval:timeoutInterval];

if (options & SDWebImageDownloaderUseNSURLCache && options & SDWebImageDownloaderIgnoreCachedResponse) {
    NSCachedURLResponse *response = [sself.sessionConfiguration.URLCache cachedResponseForRequest:request];
    // Check if the response can be read from NSURLCache, call completion block with nil
    if (response) {
        completedBlock(nil, nil, nil ,YES);
    }
}