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

Pipeline setup with DataCache is unnecessarily re-downloading original image for thumbnail request #837

Open
JValldejuli opened this issue Mar 7, 2025 · 0 comments

Comments

@JValldejuli
Copy link

JValldejuli commented Mar 7, 2025

Hello, I'm setting up my image pipeline like so:

var configuration = ImagePipeline.Configuration()
configuration.dataLoader = {
    let config = URLSessionConfiguration.default
    config.urlCache = nil
    return DataLoader(configuration: config)
}()
configuration.dataCache = {
    guard let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: AppGroupIdentifier) else {
        Log.error("Failed to initialize image pipeline data cache: Could not locate container URL")
        return nil
    }
    let dataCachePath = containerURL.appendingPathComponent(ImageDataCacheName, isDirectory: true)
    return try? DataCache(path: dataCachePath)
}()
configuration.dataCachePolicy = .storeAll

STEPS:

  1. Load a remote image with no processors and no thumbnail option (say request A)
  2. Load the same image with thumbnail option (request B)

RESULTS:
Request B freshly downloads the original image again from the network.

EXPECTED:
I thought that since request A caused the cache to save the original image in the disk cache, that request B would be able to just retrieve that original and apply the thumbnail processing. Especially since I've passed .storeAll for the dataCachePolicy and request A has no processors or thumbnail option anyways.

NOTES:
Reading the code, it appears as though perhaps TaskFetchOriginalData should be checking the disk cache for an example of cached original image data before kicking off network activity. Thoughts?

I'm using DataCache and not the URLCache because in my app the images at a URL never change and I wanted to enjoy the performance benefits mentioned in the docs https://kean-docs.github.io/nuke/documentation/nuke/getting-started/. After noticing this issue though, it does occur to me that at least at the moment URLCache would seemingly do a better job of avoiding network activity since in this case the network request would be a cache hit.

Is there maybe something wrong with how I'm setting up the pipeline?

Thank 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

1 participant