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

Incorrect original image cache key when using thumbnail options #705

Closed
hyouuu opened this issue Jun 19, 2023 · 8 comments
Closed

Incorrect original image cache key when using thumbnail options #705

hyouuu opened this issue Jun 19, 2023 · 8 comments
Labels

Comments

@hyouuu
Copy link

hyouuu commented Jun 19, 2023

Hello! We're using 11.3.1 (because our StreamChat depends on that version) and we're using the cache like this:

// setup
ImagePipeline.shared = ImagePipeline(configuration: .withDataCache)

// setting the cache to the corresponding url right after taking a photo
ImagePipeline.shared.cache.storeCachedData(imageData, for: ImageRequest(url: URL(string: remoteURL)!))

// Try to use cached data - sometimes this gives cache and if accessed later on sometimes not anymore
if let cached = ImagePipeline.shared.cache.cachedImage(for: ImageRequest(url: url)) {
// Here the cached image will be wrong - would be a previously cached image data of a different url
}

It seems the cache behavior is not deterministic and giving wrong data is pretty concerning - it feels there's some self correction actions to invalidate the cache somehow after accessing it - any insights?

Not sure if this is related to #700

@kean kean added the bug label Jun 19, 2023
@kean
Copy link
Owner

kean commented Jun 19, 2023

Thanks for the report. I'm going to try to reproduce it using unit tests. If you could provide a sample code to reproduce it, it would also be appreciated.

@kean
Copy link
Owner

kean commented Jun 22, 2023

Hey @hyouuu, can you please check if you are using the same URLs in both of these scenarios?

@hyouuu
Copy link
Author

hyouuu commented Jun 22, 2023

@kean yes I checked multiple times that the urls are exactly the same. And sorry got really occupied to provide a sample project right now

@hyouuu
Copy link
Author

hyouuu commented Jun 23, 2023

Sorry @kean just realized that I missed an important detail - I'm using the thumbnail option which might well be the root of the issues:

 var userInfo: [ImageRequest.UserInfoKey: Any]?
 let minSide = min(bounds.width, bounds.height)
 let useThumbnail = minSide > 0 && minSide < Factors.Photo.thumbnailMinSideThreshold
 if useThumbnail {
            userInfo = [
                .thumbnailKey: ImageRequest.ThumbnailOptions(maxPixelSize: Factors.Photo.thumbnailMaxPixelSize),
            ]
 }
 let request = ImageRequest(url: url, userInfo: userInfo)

Where thumbnailMinSideThreshold = 200

@kean
Copy link
Owner

kean commented Jun 24, 2023

That's perfect, thanks. That's precisely what the root cause is.

Steps

Expected Result

The pipeline stores original image data in disk cache using "https://example.com/image.jpeg" as the disk cache key

Observed Result

The pipeline stores original image data in disk cache using "https://example.com/image.jpeg+com.github/kean/nuke/thumbnail?width=400.0,height=400.0" as the disk cache key

@kean
Copy link
Owner

kean commented Jun 24, 2023

So, if you would like to remove the cached image manually, make sure to pass the exact thumbnail options in the request.

@hyouuu
Copy link
Author

hyouuu commented Jun 30, 2023

@kean I tried without the thumbnail option but the cache is still returning wrong images - please look into if there are any other possible causes

@kean kean changed the title DataCache seems to give wrong image when set locally Incorrect original image cache key when using thumbnail options Jul 22, 2023
@kean kean mentioned this issue Apr 20, 2024
@kean
Copy link
Owner

kean commented Apr 24, 2024

The thumbnail issues were fixed in Nuke 12.6. If the issues persistent, please, provide a small sample project or, ideally, a unit test with reproduction steps.

@kean kean closed this as completed Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants