Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maxCachePeriodInSecond not working #988

Closed
c0dehunter opened this issue Aug 25, 2018 · 2 comments
Closed

maxCachePeriodInSecond not working #988

c0dehunter opened this issue Aug 25, 2018 · 2 comments

Comments

@c0dehunter
Copy link

c0dehunter commented Aug 25, 2018

Issue Description

What

KF does not honor maxCachePeriodInSecond when setting cache. Expected result is that KF downloads image from URL when maxCachePeriodInSecond expires. Instead, it always loads image from cache.

Reproduce

This happens always with any URL. Here is our code:

case fiveMinutes = 5

...

iconImageView.kf.setImage(with: urlValue, options: [.transition(.fade(0.25))], cachePeriod: .fiveMinutes )

...

extension Kingfisher where Base: ImageView {
    func setImage(with resource: Resource?, options: KingfisherOptionsInfo? = nil, cachePeriod: KingfisherImageCachePeriodType?, completionHandler: CompletionHandler? = nil) {
        var newOptions: KingfisherOptionsInfo? = options
        if let cacheType = cachePeriod {
            let cache = ImageCache(name: cacheType.getChacheName)
            cache.maxCachePeriodInSecond = 60 * cacheType.rawValue
            if newOptions != nil {
                newOptions!.append(.targetCache(cache))
            } else {
                newOptions = [.targetCache(cache)]
            }
        }
        self.setImage(with: resource, options: newOptions, completionHandler: completionHandler)
    }
}
@onevcat
Copy link
Owner

onevcat commented Aug 25, 2018

maxCachePeriodInSecond is a "suggestion" of longest cache duration. It is not an aggressive way to control and clean the cache when any access happens. Basically, Kingfisher will check and clear the expired cached images when user tap Home button to send your app to background. If you need such an aggressive cleaning behavior, you may need to call cleanExpiredDiskCache(completion:) every time you try to access the images yourself, and do image retrieving in the completion handler.

@c0dehunter
Copy link
Author

c0dehunter commented Aug 25, 2018

Thank you for this guideline. It seems we were misinterpreting this value's role and will fix our code accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants