2

I fond this similar question but it's too old.

I am using the SDWebImage library to download images from a remote server.

Remote images may change (but keeping the same name) so i have to check if the remote image is changed before use the cached one.

How can i do this?

Thanks in advance (Sorry about bad english)

Community
  • 1
  • 1
polla
  • 21
  • 2

2 Answers2

1

I'm just doing this very research tonight, and based on the current implementation of SDWebImage, it looks like there's no "built-in" way to use a Conditional GET (etag or date) type request to the server to check for updates.

The way I'm exploring now is to create a unique URL, so as the server version of the image updates, append either a hash or version to the end. Something like:

http://example.com/myimage.png?v=2

And increment that version number as the image changes, but keep the myimage.png name the same since that doesn't change. That should force SDWebImage to download the new image and build a new cache for the new version of the image.

Otherwise you'd have to tweak the constant value cacheMaxCacheAge in SDImageCache.m to check more frequently than its default of 1 week.

Ryan
  • 4,658
  • 1
  • 16
  • 8
1

I did this using:

[SDWebImage sd_setImageWithURL:[NSURL URLWithString:strURL] placeholderImage:[UIImage imageNamed:@"placeholder.png"] options:SDWebImageRefreshCached];

/** * Even if the image is cached, respect the HTTP response cache control, and refresh the image from remote location if needed. * The disk caching will be handled by NSURLCache instead of SDWebImage leading to slight performance degradation. * This option helps deal with images changing behind the same request URL, e.g. Facebook graph api profile pics. * If a cached image is refreshed, the completion block is called once with the cached image and again with the final image. * * Use this flag only if you can't make your URLs static with embeded cache busting parameter. */

Thiago Pires
  • 621
  • 7
  • 20