-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Provide a simple prefetcher implementation. #249
Conversation
This functionality is available in `SDWebImage` which influenced this library, and was something we needed in migrating over. It is a simple implementation, using default managers etc. but could be expanded upon pretty easily to use different managers, downloaders, and queues etc. A utility method to check for cached images (useful when deciding whether to prefetch or not) has also been added to `KingfisherManager`. All new code is tested.
Current coverage is
|
|
||
- returns: True if the image is cached, false otherwise. | ||
*/ | ||
public func cachedImageExistsforURL(url: NSURL) -> Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although it could be useful and a quick way to check an image cached or not, I don't think it's a good idea to have a method for it here.
I believe it should only in the ImageCache
. Furthermore, since cache
of KingfisherManager
could be set by the users, it is not clear and might be confusing which cache is used for the checking.
Generally speaking, I cannot agree to add this here. We could use the same methods in ImageCache
directly. Would you mind to remove this before this p-r could be merged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll happily move it to ImageCache
but I feel it is important for our use case with prefetching as we do not care what the cache is doing. We let the library do that!
Hi, @krider2010 Thanks for the pull request. I just took a look at it and I believe it is a cool feature that could boost the speed. Except the comment above for the implementation detail, I have several concern and want to have a discussion.
How do you think about these? |
@onevcat can you confirm what it would be better to do in point 1. ? It got cut off! As for point 2. I did mention above "It is a simple implementation, using default managers etc. but could be expanded upon pretty easily to use different managers, downloaders, and queues etc." but I had no time to do this for our needs. I think it is a perfectly acceptable initial/default case. The solution here is to expand it more which I can look at doing. |
Oops, sorry for the cut off. I was considering whether we should contain a prefetcher in the manager as a member. In fact at least we are not using it at all in the manager. But yes you are right. It is already a good start point for it now. I will consider how to improve/refactor this to a better way later before it could be released. Now please just fix that obvious things and I will merge it when everything looks good! Thanks in advance! |
…ny to be specified, although a default is provided. Allow cancelling of requests too.
# Conflicts: # Tests/KingfisherTests/ImageCacheTests.swift
@onevcat let me know what you think of the latest changes :) |
Great. Thanks for this. |
Provide a simple prefetcher implementation.
This functionality is available in
SDWebImage
which influenced thislibrary, and was something we needed in migrating over.
It is a simple implementation, using default managers etc. but could be
expanded upon pretty easily to use different managers, downloaders, and
queues etc.
A utility method to check for cached images (useful when deciding
whether to prefetch or not) has also been added to
KingfisherManager
.All new code is tested.