美文网首页
SDWebImage 相同 URL, 不同 Image 处理

SDWebImage 相同 URL, 不同 Image 处理

作者: 学而不思则罔思而不学则殆 | 来源:发表于2017-09-04 19:34 被阅读100次

原因

因为 SDWebImage 的缓存机制, 相同的 URL 它就认为可以去到沙盒里面的缓存路片

解决方法

NSString *testImageUrl = "www.你的image.com";
[_IMG sd_setImageWithURL:[NSURL URLWithString:testImageUrl] placeholderImage:[UIImage imageNamed:@"1.png"] options:SDWebImageRefreshCached];

SDWebImageManager.m文件中,大概176行左右吧,把之前的代码:(如下)

if (image && options & SDWebImageRefreshCached) {
    // force progressive off if image already cached but forced refreshing
    downloaderOptions &= ~SDWebImageDownloaderProgressiveDownload;
    // ignore image read from NSURLCache if image if cached but force refreshing
    downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse;
}

更换成如下代码:

if (image && options & SDWebImageRefreshCached) {
    // force progressive off if image already cached but forced refreshing
    downloaderOptions &= ~SDWebImageDownloaderProgressiveDownload;
    // remove SDWebImageDownloaderUseNSURLCache flag
    downloaderOptions &= ~SDWebImageDownloaderUseNSURLCache;
    // ignore image read from NSURLCache if image if cached but force refreshing
    downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse;
}

相关文章

网友评论

      本文标题:SDWebImage 相同 URL, 不同 Image 处理

      本文链接:https://www.haomeiwen.com/subject/dzbxxxtx.html