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

determining if image was loaded from cache #15

Open
rjuzaszek opened this issue Jun 14, 2017 · 5 comments
Open

determining if image was loaded from cache #15

rjuzaszek opened this issue Jun 14, 2017 · 5 comments

Comments

@rjuzaszek
Copy link

rjuzaszek commented Jun 14, 2017

Hello, great work, really appreciate simplicity of this lib, but I found myself in a situation when I would like to determine if image was really downloaded or loaded from a cache - for example to show or not to show an animation, is there a simple way to determine that (maybe using duration field in MoaImage)?

desired example:

profileImage.moa.onSuccessAsync = {  image in
    if !image.loadedFromCache {
        UIView.animate(withDuration: 0.3, animations: {
            self.profileImage.layer.opacity = 1.0
        })
    }
   return image
}
@evgenyneu
Copy link
Owner

evgenyneu commented Jun 14, 2017

Hi @rjuzaszek, good question. I don't know the answer, unfortunately. The library uses the built-in URLSession class for downloading the image and caching. I did a quick search and could not find a way to tell if data was taken from cache.

Do you need to display a "loading..." spinner animation?

@rjuzaszek
Copy link
Author

Thanks for reply.
Yes I'm displaying it, but the problem is to not to display the animation if image is taken from cache which causes the image blink instantly after showing the VC, which I would like to avoid, if I wouldn't find any simple way I think I'll just skip opacity animation in every situation.

@evgenyneu
Copy link
Owner

evgenyneu commented Jun 14, 2017

Oh, I see now, thanks for clarification. So your goal is to show the image instantly if it's taken from cache or fade it in if it's downloaded from the network?

@rjuzaszek
Copy link
Author

Yes

@evgenyneu
Copy link
Owner

Interesting ... I can't think of any good solution at the moment. My first thought was to check the duration of time elapsed between assigning the URL and calling onSuccess. If it's less than N milliseconds, then it could be from cache. But it does not look like a robust solution to me. A more reliable approach would be to either always show image with or without animation. I am sorry, I could not help you. :(

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