如何在没有任何缓存的情况下为一个实例使用SDWebImage [英] How to use SDWebImage without any cache for one instance
问题描述
我在桌面上显示图像时几乎都使用 SDWebImage 图像下载/缓存库查看。
I use the SDWebImage image downloading/caching library pretty much any time I display an image in a table view.
我通常会这样实现它(在表视图中 cellForRowAtIndexPath
方法)。
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.
如果我想使用SDWebImage的简单性(使用占位符/强大的下载代码) - 但只有一个地方没有缓存那么。
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.
我知道如何在整个SDWebImage中禁用缓存,但我不知道如何调用 setImageWithUrl:placeholderImage:
确保SDWebImage没有t使用任何缓存?
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).
推荐答案
我建议远离UIImageView上的类别并创建自己的SDWebImageManager版本。如果您自己使用SDImageCache类,您将获得更多控制权。
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.
来自SDWebImageManager本身的Heres和示例:
Heres and example right from SDWebImageManager itself:
[[SDImageCache sharedImageCache] storeImage:image
imageData:downloader.imageData
forKey:[downloader.url absoluteString]
toDisk:NO];
toDisk可能是我将BOOL更改为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];
SDWebImageManager代码很容易理解,我想你不需要重新发明大部分代码,只需几个重要部分来满足您的需求。
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!