public final class ImagePrefetcher
Prefetches and caches images to eliminate delays when requesting the same images later.
The prefetcher cancels all of the outstanding tasks when deallocated.
ImagePrefetcher methods are thread-safe and are optimized to be used
even from the main thread during scrolling.
public init(pipeline: ImagePipeline = ImagePipeline.shared, destination: Destination = .memoryCache, maxConcurrentRequestCount: Int = 2)
maxConcurrentRequestCount: 2 by default.
public var isPaused: Bool = false
Pauses the prefetching.
public func startPrefetching(with requests: [ImageRequestConvertible])
Starts prefetching images for the given requests.
When you need to display the same image later, use the
or the view extensions to load it as usual. The pipeline will take care
of coalescing the requests to avoid any duplicate work.
The priority of the requests is set to the priority of the prefetcher
.low by default).
public func stopPrefetching(with requests: [ImageRequestConvertible])
Stops prefetching images for the given requests and cancels outstanding requests.
You don't need to balance the number of
If you have multiple screens with prefetching, create multiple instances
public func stopPrefetching()
Stops all prefetching tasks.