How to use SDWebImage without any cache for one instance
Asked Answered
A

6

11

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

Acquiescence answered 6/1, 2012 at 0:10 Comment(0)
S
7

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.

Scorpio answered 15/2, 2012 at 9:55 Comment(0)
H
6

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,
Hathaway answered 30/4, 2014 at 2:33 Comment(0)
T
3
  1. Swift 4.2
  2. Xcode: 10.0
  3. SDWebImage: ~>4.0

SDImageCache.shared().config.shouldCacheImagesInMemory = false

Taproom answered 14/2, 2019 at 23:13 Comment(1)
Any way to accomplish this for just a specific call of downloadImage?Fed
B
1

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

Baynebridge answered 15/2, 2017 at 9:36 Comment(0)
S
1

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

Stickybeak answered 8/3, 2018 at 13:33 Comment(0)
E
0

You should use SDWebImageManager.shared.loadImage with fromLoaderOnly option

Excitation answered 13/1, 2023 at 11:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.