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

Provide a simple prefetcher implementation. #249

Merged
merged 5 commits into from
Mar 3, 2016

Conversation

krider2010
Copy link
Contributor

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.

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.
@codecov-io
Copy link

Current coverage is 78.38%

Merging #249 into master will increase coverage by +0.98% as of bf24397

@@            master    #249   diff @@
======================================
  Files           11      12     +1
  Stmts         1257    1314    +57
  Branches         0       0       
  Methods          0       0       
======================================
+ Hit            973    1030    +57
  Partial          0       0       
  Missed         284     284       

Review entire Coverage Diff as of bf24397

Powered by Codecov. Updated on successful CI builds.


- returns: True if the image is cached, false otherwise.
*/
public func cachedImageExistsforURL(url: NSURL) -> Bool {
Copy link
Owner

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?

Copy link
Contributor Author

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!

@onevcat
Copy link
Owner

onevcat commented Feb 27, 2016

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.

  1. The KingfisherManager type is now used as a "glue" between ImageDownloader and ImageCache. Framework users/image extension could use KingfisherManager to download and cache images without knowing the detail of downloader and cache. However, I don't think it is the situation for ImagePrefetcher. The prefetcher property is even not used in KingfisherManager. It would be better to
  2. Now ImagePrefetcher is relying KingfisherManager and caching the downloaded images to the manager's cache. It is probably not a good choice. There is no chance for a user who wants to cache the prefetched images to another cache besides the manager's one.

How do you think about these?

@krider2010
Copy link
Contributor Author

@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.

@onevcat
Copy link
Owner

onevcat commented Feb 27, 2016

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
@krider2010
Copy link
Contributor Author

@onevcat let me know what you think of the latest changes :)

@onevcat
Copy link
Owner

onevcat commented Mar 3, 2016

Great. Thanks for this.

onevcat added a commit that referenced this pull request Mar 3, 2016
Provide a simple prefetcher implementation.
@onevcat onevcat merged commit 1d39c83 into onevcat:master Mar 3, 2016
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

Successfully merging this pull request may close these issues.

4 participants