-
-
Notifications
You must be signed in to change notification settings - Fork 531
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
[Feature Request] Add cacheType to ImageResponse #361
Comments
Hi, I was considering adding a feature like that, I think I have something similar in backlog. I was also thinking adding a set of sources to fetch the image from in the request. Both of these features could use the same enum. The reason why I haven't implemented it yet is that there were no demand for this feature. Could you please give an example where you would need to know whether the image was returns from cache or not? |
Here is an example: So the code looks something like that:
In this code I'm checking the response.urlResponse for nil, which is not correctly. If there will be the cacheType we can check it |
I use a slightly different approach in Nuke to implement this sort of thing. If you look into // Quick synchronous memory cache lookup
if let image = pipeline.cachedImage(for: request) {
let response = ImageResponse(container: image)
// Display image without animation. This makes sure no animations are run, and no frames are skipped. Would that work for you? |
As I know it doesn't work if there is no cache in memory, but there is in the disk. |
I'm wondering, how do you retrieve images from disk cache? |
First of all I've inited like that:
Then I download image like that:
So if there is no cache in memory, but is on disk |
Oh, so the goal is not run animations when the response arrives quickly (e.g. from disk cache)? I think the code that you currently have is fine. I'm not against adding this new API, but it is probably not something to prioritize as there is already an existing way to do that, and it's quite niche requirement. Many people rely on URLCache. For URLCache there is no (clear) way to tell whether the request came form the network or from cache. A better check would probably be: did the response come within 300ms, if yes, don't run animations. |
|
Hello!
It will be very helpful if ImageResponse will have cacheType property, which contains
.memory/.disk/nil
. It will help to recognize was this image got from cache or not in complete block ofNuke.loadImage
The text was updated successfully, but these errors were encountered: