Customizing Requests

How to change request priority, cache policy, processors, and more

ImageRequest allows you to set image processors, change the request priority and more.

let request = ImageRequest(
    url: URL(string: "http://..."),
    processors: [ImageProcessors.Resize(size: imageView.bounds.size)],
    cachePolicy: .reloadIgnoringCacheData,
    priority: .high
Nuke.loadImage(with: url, into: imageView)

Priority #

The execution priority of the request. The priority affects the order in which the image requests are executed. By default, .normal1.

You can change the priority of a running task using ImageTask.priority.

var request = ImageRequest(url: URL(string: "http://..."))
request.priority = .high

Processors #

Apply image processors.

var request = ImageRequest(url: URL(string: "http://..."))
request.processors = [ImageProcessors.Resize(size: imageView.bounds.size)]

All built-in processors can be found in ImageProcessors namespace.

Another way to apply processors is by setting the default processors on ImagePipeline.Configuration.

See “Image Processing” for more information on image processing.

URLRequest #

The request can be instantiated either with a URL or with a URLRequest.

let urlRequest = URLRequest(url: imageUrl, cachePolicy: .returnCacheDataDontLoad)
let request = ImageRequest(urlRequest: urlRequest)

Cache Policy #

By default, the pipeline makes full use of all of its caching layers. You can change this behavior using ImageRequest.CachePolicy. For example, you can ignore local caches using .reloadIgnoringCachedData policy.

var request = ImageRequest(url: URL(string: "http://..."))
request.cachePolicy = .reloadIgnoringCachedData

If you initialize the request with URLRequest, make sure to provide the correct policy.

See “Caching” for more information on caching.

Other Options #

There are some additional options available via ImageRequestOptions. For example, you can provide a filteredURL to be used as a key for caching in case the URL contains transient query parameters.

var request = ImageRequest(url: URL(string: ""))
request.options.filteredURL = ""
  1. The priority management is key for Nuke performance. ImagePrefetcher uses .low priority to avoid interfering with .normal requests.