如何在一个实例中使用没有任何缓存的 SDWebImage
每当我在表格视图中显示图像时,我几乎都会使用 SDWebImage 图像下载/缓存库。
我通常会像这样实现它(在表视图 cellForRowAtIndexPath 方法中)。
[cell.imageView setImageWithURL:
[NSURL URLWithString:@"http://asite.com/animage.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
如果有的话,这将加载一个缓存版本。
如果我想在一个地方使用 SDWebImage 的简单性(带有占位符/强大的下载代码),但没有缓存,该怎么办?
我知道如何在整个 SDWebImage 中禁用缓存,但我不知道如何调用 setImageWithUrl: placeholderImage:
确保 SDWebImage 不使用任何缓存?
我想这样做的原因是我使用它在表格视图中显示网络摄像头(显然,您希望每次都更新)。
I use the SDWebImage image downloading/caching library pretty much any time I display an image in a table view.
I would usually implement it like so (in a table view cellForRowAtIndexPath
method).
[cell.imageView setImageWithURL:
[NSURL URLWithString:@"http://asite.com/animage.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
And that would load a cached version if it had one.
What about if I wanted to use the simplicity of SDWebImage (with the placeholder / robust downloading code) - but without the cache in just one place.
I know how to disable caching throughout SDWebImage, but I don't know how you would call setImageWithUrl: placeholderImage:
making sure that SDWebImage doesn't use any cache?
The reason I want to do this is I'm using it to display webcams in a table view (obviously, you want this updated every time).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我建议放弃 UIImageView 上的类别并创建您自己的 SDWebImageManager 版本。如果您自己使用 SDImageCache 类,您将获得更多控制权。
以下是 SDWebImageManager 本身的示例:
toDisk 可能是我将 BOOL 更改为 NO 的地方,默认管理器使用磁盘缓存。您可能还想经常清除内存以支持流图像:
SDWebImageManager 代码很容易理解,我想您不需要重新发明其中的大部分内容,只需要几个重要的部分来满足您的需求。
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:
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:
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.
干得好。确保您获得最新版本的 SDWebImage:
来自 SDWebImageManager.h:
Here you go. Make sure you get the latest version of SDWebImage:
From SDWebImageManager.h:
您只需使用
SDImageCache
中的shouldCacheImagesInMemory
属性并将其设置为 NO。此功能在 3.7.4+ 中可用。
You just need to use the
shouldCacheImagesInMemory
property fromSDImageCache
and set it to NO.This feature available in 3.7.4+.
您可以使用 SDWebImageDownloader。它不缓存数据。
You can use SDWebImageDownloader. It doesn't cache data.
您应该将 SDWebImageManager.shared.loadImage 与 fromLoaderOnly 选项一起使用
You should use SDWebImageManager.shared.loadImage with fromLoaderOnly option