Nuke icon indicating copy to clipboard operation
Nuke copied to clipboard

Image download requests not deduplicated

Open MartinStrambach opened this issue 1 year ago • 1 comments

I have the following setup:

struct Model {
		let url: String
		let size: CGSize
		let priority: ImageRequest.Priority
		let cacheType: CacheType
		let transaction: Transaction
		let additionalProcessor: [ImageProcessing]
}
LazyImage(url: URL(string: model.url), transaction: model.transaction) { state in
			if let image = state.image {
				image
					.resizable()
					.aspectRatio(contentMode: .fill)
					.frame(width: model.size.width, height: model.size.height)
			}
		}
		.priority(model.priority)
		.processors([.resize(size: model.size)] + model.additionalProcessor)
		.pipeline(
			ImagePipeline(
				configuration: .withDataCache(
					name: model.cacheType.rawValue,
					sizeLimit: 1024 * 1024 * model.cacheType.size
				)
			)
		)
}

The use case is the same as in the documentation where I have two images (one blurred) on top of each other. If I comment out ImagePipeline, I see one request per unique image. Unfortunately, with ImagePipeline with disk caching it doesn't work and 2 requests are fired for a unique image.

Xcode 16.2 Nuke 12.8 iOS 18.2

MartinStrambach avatar Dec 15 '24 14:12 MartinStrambach

Hi, looks like your issue is that you are creating a fresh ImagePipeline for each request. You need to configure the ImagePipeline.shared singleton instance and stop passing a custom image pipeline to each request.

If for whatever reason you don't want to use ImagePipeline.shared, you can still pass a custom image pipeline but just make sure you are reusing it for all requests in order to enjoy task coalescing.

JValldejuli avatar Apr 18 '25 08:04 JValldejuli