如果使用pods缓存图片并异步下载,我需要下载两次图片吗?
do I download the image twice if use pods to cache the image and download it asynchronously?
我是编程新手,在iOS开发中,尝试使用kingfisher异步缓存和下载图片。
我有一个下载网址,从那个 link 下载的图片将用于 2 个图片查看。对于 blurryImageView 和 posterImageView。
blurryImageView 将用作背景,以防万一来自用户的图像不符合下图所示的所需垂直水平比例
我的问题是,如果我从那个 link 下载并将用于 2 个图像查看,我实际上是下载了两次还是只下载了一次?
这是我使用的简化代码:
import Kingfisher
@IBOutlet weak var posterImageView: ImageView!
@IBOutlet weak var blurryImageView: ImageView!
override func viewDidLoad() {
super.viewDidLoad()
guard let urlPoster = URL(string: imagePathString) else {return}
blurryImageView.kf.setImage(with: urlPoster)
posterImageView.kf.setImage(with: urlPoster)
}
正如您在上面的代码中看到的,图像将被异步下载,并且当 posterImageView.kf.setImage(with: urlPoster)
被触发时,图像(我假设)仍未完成从 blurryImageView.kf.setImage(with: urlPoster)
下载.所以我担心它会被下载两次,效率不高。我希望它只下载一次。只想下载一次怎么办
别担心它不会再次下载。如果您阅读 kingfisher 文档,它会提到一旦图像被下载,它们就会被缓存。因此,下次您从 url 调用图像时,它会从缓存中获取。
这是 kingfisher 文档中的行
Kingfisher will download the image from url, send it to both the
memory cache and the disk cache, and display it in imageView. When you
use the same code later, the image will be retrieved from cache and
shown immediately.
我是编程新手,在iOS开发中,尝试使用kingfisher异步缓存和下载图片。
我有一个下载网址,从那个 link 下载的图片将用于 2 个图片查看。对于 blurryImageView 和 posterImageView。
blurryImageView 将用作背景,以防万一来自用户的图像不符合下图所示的所需垂直水平比例
我的问题是,如果我从那个 link 下载并将用于 2 个图像查看,我实际上是下载了两次还是只下载了一次?
这是我使用的简化代码:
import Kingfisher
@IBOutlet weak var posterImageView: ImageView!
@IBOutlet weak var blurryImageView: ImageView!
override func viewDidLoad() {
super.viewDidLoad()
guard let urlPoster = URL(string: imagePathString) else {return}
blurryImageView.kf.setImage(with: urlPoster)
posterImageView.kf.setImage(with: urlPoster)
}
正如您在上面的代码中看到的,图像将被异步下载,并且当 posterImageView.kf.setImage(with: urlPoster)
被触发时,图像(我假设)仍未完成从 blurryImageView.kf.setImage(with: urlPoster)
下载.所以我担心它会被下载两次,效率不高。我希望它只下载一次。只想下载一次怎么办
别担心它不会再次下载。如果您阅读 kingfisher 文档,它会提到一旦图像被下载,它们就会被缓存。因此,下次您从 url 调用图像时,它会从缓存中获取。
这是 kingfisher 文档中的行
Kingfisher will download the image from url, send it to both the memory cache and the disk cache, and display it in imageView. When you use the same code later, the image will be retrieved from cache and shown immediately.