-
Notifications
You must be signed in to change notification settings - Fork 35
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
Get from cache then network? #3
Comments
Hello, thank you for this great question! KFSwiftImageLoader doesn't currently have an easy way to do this as the emphasis is currently put on placeholder images. placeholderCache.cacheImage(imageView.image, forKey: urlString)
// The next time the app is launched, do something like:
imageView.loadImageFromURLString(urlString, placeholderImage: placeholderCache.cachedImageForKey(urlString)) {
(finished, error) in
// Cache the new image as a future placeholder.
placeholderCache.cacheImage(imageView.image, forKey: urlString)
} |
Wouldnt the loadImageFromURLString return the already cached image in this case? |
Yes, sorry about that, I forgot to include the following line as well: KFImageCacheManager.sharedInstance.diskCacheMaxAge = 0 You should put that line in application:DidFinishLaunchingWithOptions: so that the file cache is purged when the app loads for the first time, and then from there since you've maintained your own placeholderCache, you can pull the previously cached image and put it as a placeholder. Since there won't be a memory cache on first load, the image won't be loaded from cache in this case (nor the file cache due to the above line). This solution is only good for first time load scenarios. I'll be adding this feature to the next version of KFSwiftImageLoader in the coming weeks as I'm going to overhaul the tool for Swift 2.0 as well by then. |
How would i acheive this? I want to use cache to display whatever is available from cache on initial load, and then request the image from network if available - re-firing the same callback closure.
The text was updated successfully, but these errors were encountered: