How to set max period on image in cache and clear expired items manually using Kingfisher(or AlamofireImage)?

Viewed 1234

I would like to use multiple cache scenarios for multiple groups like: 1-this image group should exist refresh every 60 seconds. 2-this image group should exist forever unless memory warning occurs. I don't know how to implement multiple cache programs with one library like AlamofireImage(or Kingfisher). I wrote this code but it can not clear expired images in folder(I dont want to purge all the cache folder content):

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()}
1 Answers
Related