我想为多个组使用多个缓存方案,例如:1-此图像组应该每 60 秒刷新一次。2-除非出现内存警告,否则该图像组应该永远存在。我不知道如何用一个像 AlamofireImage(或 Kingfisher)这样的库来实现多个缓存程序。我写了这段代码,但它无法清除文件夹中过期的图像(我不想清除所有缓存文件夹内容):
let downloader = ImageDownloader(name: "shortlived_image_downloader")
let cache = ImageCache(name: "shortlived_cache")
cache.maxCachePeriodInSecond = 60
cell.onPlayingImageView.kf.setImage(with: url,
placeholder: UIImage(named:"Placeholder_S"),
options: [.transition(ImageTransition.fade(0.25)),
.downloader(downloader),
.targetCache(cache)],
progressBlock: nil,
completionHandler: nil)
func clearKFShortLiveCache() {
let cache = ImageCache(name: "shortlived_cache")
cache.clearMemoryCache()
cache.cleanExpiredDiskCache()}