如何在一个实例中使用没有任何缓存的 SDWebImage

发布于 2024-12-24 21:32:59 字数 617 浏览 5 评论 0原文

每当我在表格视图中显示图像时,我几乎都会使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

热风软妹 2024-12-31 21:32:59

我建议放弃 UIImageView 上的类别并创建您自己的 SDWebImageManager 版本。如果您自己使用 SDImageCache 类,您将获得更多控制权。

以下是 SDWebImageManager 本身的示例:

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

toDisk 可能是我将 BOOL 更改为 NO 的地方,默认管理器使用磁盘缓存。您可能还想经常清除内存以支持流图像:

[[SDImageCache sharedImageCache] clearMemory];

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:

[[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.

Hello爱情风 2024-12-31 21:32:59

干得好。确保您获得最新版本的 SDWebImage:

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

来自 SDWebImageManager.h:

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

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,
℡Ms空城旧梦 2024-12-31 21:32:59
  1. Swift 4.2
  2. Xcode: 10.0
  3. SDWebImage: ~>4.0

SDImageCache.shared().config.shouldCacheImagesInMemory = false

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

SDImageCache.shared().config.shouldCacheImagesInMemory = false

匿名的好友 2024-12-31 21:32:59

您只需使用 SDImageCache 中的 shouldCacheImagesInMemory 属性并将其设置为 NO。
此功能在 3.7.4+ 中可用。

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

雨的味道风的声音 2024-12-31 21:32:59

您可以使用 SDWebImageDownloader。它不缓存数据。

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

瑾兮 2024-12-31 21:32:59

您应该将 SDWebImageManager.shared.loadImagefromLoaderOnly 选项一起使用

You should use SDWebImageManager.shared.loadImage with fromLoaderOnly option

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文