Nike Kov
Nike Kov

Reputation: 13708

Kingfisher how it checks if need to refresh image?

I'm using a Kingfisher lib to manage images. The server refresh image every hour. Kingfisher not refreshing the image. Why?

MY INVESTIGATION: I've read cheat sheet and wiki and found out that the cache is marking as expired after 5 minutes for memory and 7 days for disk. When app did enter background and receive UIApplicationDidEnterBackgroundNotification the library performs backgroundCleanExpiredDiskCache that cleans the disk cache. Also there is a .forceRefresh option to load the image from web every time.

But i don't need to load image every time. I just need to refresh it when the new image appear on the same image url. How this works? I think it should be some field that received from the server, that can tell - you need to update your image, and the lib should manage this field, isn't it?

Upvotes: 0

Views: 469

Answers (1)

Okan T.
Okan T.

Reputation: 78

This question had asked a long time ago. I've included SwiftUI sample code below to help now or in the future.

In swiftUI you can use modifiers which are diskCacheExpiration() or memoryCacheExpiration() which you need with time type.

if let url = URL(string: stringUrl) {
KFImage(url)
    .resizable()
    .diskCacheExpiration(.seconds(60)) <--- Here enter time which you want
    .memoryCacheExpiration(.seconds(60)) <--- Here enter time which you want
}

Upvotes: 0

Related Questions