简体   繁体   English

SDWebImage缓存正在花时间从uicollectionview单元中的缓存加载图像

[英]SDWebImage caching is taking time to load the image from cache in uicollectionview cell

I am using SDWebImage library to load images in a collection view . 我正在使用SDWebImage库在集合视图中加载图像。

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 ) (占位符图像有时显示2-3秒甚至更多)

Code to load image using SDWebImage: 使用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 . 问题:我不知道为什么集合视图单元无法使用sdwebimage立即加载图像。 As it says sdwebimage is best library for image caching . 就像说的那样,sdwebimage是用于图像缓存的最佳库。 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 https://github.com/rs/SDWebImage/issues/138

Thanks in advance. 提前致谢。

From SDWebImage documentation, for refreshCached 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. 

You should not use refreshCached if you don't want images to be cached unless you get different images in same URL. 如果您不希望缓存图像,则不应使用refreshCached ,除非您在同一URL中获得了不同的图像。 Leave it to default set up and it will handle everything for you. 将其保留为默认设置,它将为您处理所有事情。

EDIT: Just leave options as empty array, []. 编辑:只需将options保留为空数组[]。 It should continue with default setup. 它应继续使用默认设置。 Your delay is probably because you still have refreshedCache in your code. 延迟的原因可能是因为您的代码中仍然有refreshedCache

cell.imgPost.sd_setImage(with: NSURL() as URL!, placeholderImage: UIImage(), options: [], progress: { (_, _) in

}, completed: { (_, _, _, _) in

})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM