[英]SDWebImage caching is taking time to load the image from cache in uicollectionview cell
我正在使用SDWebImage庫在集合視圖中加載圖像。
庫從服務器和緩存下載圖像,但是當我退出應用程序並重新運行時,從緩存加載圖像會花費一些時間。 (占位符圖像有時顯示2-3秒甚至更多)
使用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
}
}
})
這里使用的緩存選項是刷新緩存。
問題:我不知道為什么集合視圖單元無法使用sdwebimage立即加載圖像。 就像說的那樣,sdwebimage是用於圖像緩存的最佳庫。 誰能指出解決方案/問題?
編輯我確實在他們的圖書館中留下了評論,我認為這從來都不是一個好的圖書館。 https://github.com/rs/SDWebImage/issues/138
提前致謝。
從SDWebImage
文檔中,獲取refreshCached
* 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, eg 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 embedded cache busting parameter.
如果您不希望緩存圖像,則不應使用refreshCached
,除非您在同一URL中獲得了不同的圖像。 將其保留為默認設置,它將為您處理所有事情。
編輯:只需將options
保留為空數組[]。 它應繼續使用默認設置。 延遲的原因可能是因為您的代碼中仍然有refreshedCache
。
cell.imgPost.sd_setImage(with: NSURL() as URL!, placeholderImage: UIImage(), options: [], progress: { (_, _) in
}, completed: { (_, _, _, _) in
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.