New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to preserve images in cache even in case of a HTTP 300/400/500 response from server? #223
Comments
Why not use You can read documentation firstly and search for the result |
When you config
|
@dreampiggy Thanks for your response. Interestingly, although I added the following code to my app:
Still an
Any ideas what is wrong with my setup? Thanks! |
This is NSIndexSet. Your "[200]" menas only HTTP 200 will treat as success. I menas you provide a IndexSet with range like [200, 600) or something |
Maybe you misunderstand that refreshCache means. That strange option behave:
|
Maybe you misunderstand that refreshCache means. That strange option behave:
|
For you case, you can either:
class MyImageLoader : SDImageLoaderProtocol {
func loadImage(with: url, callback) {
let loadedImage = context[.loaderCachedImage]
SDImageDownloader.shared.loadImage(with: url) { image, data, error in
if error && loadedImage {
callback(loadedImage, nil, NSError(domain: SDWebImageErrorDomain code: .cacheNotModified))
return
}
callback(image, data, error)
}
}
} Is this feature really useful in general ? |
I think that in general it would be useful to have a built-in option to keep cached images as long as there is a valid new version of them. If the remote server containing the images is broken for whatever reason (developer mistake, hardware issue) and returns invalid response codes such as 403, 404, 500, ... the user of the mobile app would still see the correct image. |
Seems a feature request. Maybe we can create a issue in https://github.com/SDWebImage/SDWebImage/issues and reference this. It's not hard to implements, but need a new options like |
I like the |
It's OK to fire issue first. The detail API name actually we can talk in PR. |
I'm using
SDWebImage
in order to preserve data bandwidth with.refreshCached
in order to update images from time to time:This works great even if the network is down, images are served from cache.
However, if the URL of the image returns 300/400/500, etc... - which may happen - SDWebImage erased the image from cache and no image is displayed. This is not a desirable behaviour as 1) servers can be down temporarily for maintenance, 2) public WiFi networks return 302 Moved for unauthenticated users, etc - I would prefer keeping images in cache until a new valid image is downloaded.
Is that possible?
The text was updated successfully, but these errors were encountered: