I am using SDWebImage library to load images in a collection view .
Library downloads the image from server and caches but when I quit my app and re-run , it takes time to load image from cache. ( placeholder image is displayed for 2-3 secs sometimes even more )
Code to load image using SDWebImage:
cell.imgPost.sd_setImage(with: URL(string: (post.lowQualityImgUrl) ?? ""), placeholderImage: UIImage(named:"greybg") , options: .refreshCached, progress: { (recievedSize, expectedSize) in
progressIndicatorView.progress = CGFloat(recievedSize)/CGFloat(expectedSize)
}, completed: { (image, error, cachetype, url) in
if image != nil{
DispatchQueue.main.async {
progresView.removeFromSuperview()
progressIndicatorView.removeFromSuperview()
cell.progressIndicatorView?.isHidden = true
cell.imgPost.image = image
}
}
})
Here the caching option used is refresh cache.
Question: I don't know why collection view cells can't load the images instantly using sdwebimage . As it says sdwebimage is best library for image caching . Can anyone point out solution /problem ?
EDIT I did left comment in their library , I think it's never a good library. https://github.com/rs/SDWebImage/issues/138
Thanks in advance.
From
SDWebImage
documentation, forrefreshCached
You should not use
refreshCached
if you don't want images to be cached unless you get different images in same URL. Leave it to default set up and it will handle everything for you.EDIT: Just leave
options
as empty array, []. It should continue with default setup. Your delay is probably because you still haverefreshedCache
in your code.