[iOS] SDWebImage 刷新图片缓存方法

将 SDWebImageManager.m 文件中的 downloadImageWithURL 方法中的 ( 代码在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 is cached but force refreshing
  downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse;
}

之后在工程中使用如下方法:

[self.imageView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage new] options:SDWebImageRefreshCached];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容