How to use SDWebImage without any cache for one instance

删除回忆录丶 提交于 2019-12-04 03:16:43

I recommend moving away from the Category on UIImageView and creating your own version of SDWebImageManager. You'd get more control if you use the class SDImageCache yourself.

Heres and example right from SDWebImageManager itself:

[[SDImageCache sharedImageCache] storeImage:image
                                  imageData:downloader.imageData
                                     forKey:[downloader.url absoluteString]
                                     toDisk:NO];

toDisk is probably where I changed the BOOL to NO, the default manager uses disk caching. You may also want to clear the memory every so often to support your streaming images:

[[SDImageCache sharedImageCache] clearMemory];

The SDWebImageManager code is easy to follow and I imagine you won't need to reinvent most of it, just a few important portions to suit your needs.

Here you go. Make sure you get the latest version of SDWebImage:

[anImageView setImageWithURL:[NSURL URLWithString:@"http://asite.com/animage.jpg"]
            placeholderImage:[UIImage imageNamed:@"placeholder.png"]
                     options:SDWebImageCacheMemoryOnly];

From SDWebImageManager.h:

/**
 * This flag disables on-disk caching
 */
SDWebImageCacheMemoryOnly = 1 << 2,

You just need to use the shouldCacheImagesInMemory property from SDImageCache and set it to NO. This feature available in 3.7.4+.

You can use SDWebImageDownloader. It doesn't cache data.

  1. Swift 4.2
  2. Xcode: 10.0
  3. SDWebImage: ~>4.0

SDImageCache.shared().config.shouldCacheImagesInMemory = false

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!