How to use SDWebImage without cache for a single instance

I use the SDWebImage library to load / cache images almost anytime when I display the image as a table.

I would usually implement it like this (as a cellForRowAtIndexPath table).

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

And this will load the cached version, if any.

How about if I wanted to use the simplicity of SDWebImage (via firmware / reliable download code), but without a cache in only one place.

I know how to disable caching in SDWebImage, but I donโ€™t know what you would call setImageWithUrl: placeholderImage: to make sure SDWebImage is not using a cache?

The reason I want to do this is to use it to display webcams as a table (obviously, you want this update every time).

+7
source share
4 answers

I recommend dropping the category in UIImageView and creating your own version of SDWebImageManager. You will get more control if you yourself use the SDImageCache class.

Heres and an example directly from the SDWebImageManager itself:

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

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

 [[SDImageCache sharedImageCache] clearMemory]; 

The SDWebImageManager code is easy to track, and I suppose you wonโ€™t need to invent most of it, just a few important parts to satisfy your needs.

+6
source

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, 
+3
source

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

0
source

You can use SDWebImageDownloader. It does not cache data.

0
source

All Articles