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()}
In Kingfisher,
You can clear different types of
cacheusing:To set
cache size and timeaccording to your requirement, you can use:Image group should exist forever unless memory warning occurs: It is handled automatically by
Kingfisher.AutoPurgingImageCacheconcept is not handled byKingfisher. This is supported byAlamofireImage. InKingfisher, you have to handleauto purgingbased onlast access dateyourself.For details on these properties and methods, you can refer to:
https://github.com/onevcat/Kingfisher/wiki/Cheat-Sheet http://cocoadocs.org/docsets/Kingfisher/1.1.2/Classes/ImageCache.html