LoginSignup
12
8

More than 5 years have passed since last update.

Kingfisherの詳しい使い方(チートシート+α)

Posted at

Kingfisherのキャッシュについて

  • 原則キャッシュされる
  • 自分でキャッシュする仕組みを作る事もできる

メモリだけで運用したい

読み込み時

imageView.kf.setImage(with: ImageResource(downloadURL: pictureURL), options: [.cacheMemoryOnly], completionHandler: { (image, error, cacheType, imageUrl) in
})

キャッシュに存在するか

if (CacheType.none != ImageCache.default.imageCachedType(forKey: pictureURL.absoluteString) {
// ある
}

その他

独自のImageCacheを作る

let cache = ImageCache(name: "longer_cache")

ディスクキャッシュのサイズを変更

cache.maxDiskCacheSize = 60 * 60 * 24 * 30

ディスクキャッシュの期間を変更

// 3日に変更。デフォルトでは7日間
cache.maxCachePeriodInSecond = 60 * 60 * 24 * 3

キャッシュを利用せず強制的に読み込み&キャッシュ更新

imageView.kf.setImage(with: url, options: [.forceRefresh])

キャッシュを指定

let cache = ImageCache.default
imageView.kf.setImage(with: url, options: [.targetCache(cache)])

今すぐキャッシュを消したい

ImageCache.default.clearMemoryCache()

参考

12
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
8