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

While using ImagePrefetcher(), RetryStrategy is not working. #2314

Open
3 tasks done
Ayushjain745 opened this issue Oct 25, 2024 · 1 comment
Open
3 tasks done

While using ImagePrefetcher(), RetryStrategy is not working. #2314

Ayushjain745 opened this issue Oct 25, 2024 · 1 comment

Comments

@Ayushjain745
Copy link

Ayushjain745 commented Oct 25, 2024

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

Issue Description

I have created ImagePrefetcher() and with the help of KingfisherOptionsInfo I have given the RetryStrategy but it seems the strategy not working.

What


func prefetchAllImages(completion: @escaping (Bool) -> Void) {
        ImageCache.default.clearDiskCache()
        ImageCache.default.clearMemoryCache()
        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
            // Get all image URLs from ImageResourceUrl enum
            let urls = ImageResourceUrl.allCases.map { $0.url }
            let downloader = ImageDownloader(name: "custom")
            downloader.downloadTimeout = 45
            // Retry strategy: attempt up to 3 retries with a 1-second interval
            let retryStrategy = DelayRetryStrategy(maxRetryCount: 3, retryInterval: .seconds(1))
            // Set options with custom downloader and retry strategy
            let kingFisherOptions: KingfisherOptionsInfo = [
                .downloader(downloader),
                .retryStrategy(retryStrategy)
            ]

            // Prefetch images with completion handler
            let prefetcher = ImagePrefetcher(urls: urls, options: kingFisherOptions, progressBlock: { skippedResources, failedResources, completedResources in
                // You can use these counts for progress feedback
                print("Ayush Completed: \(completedResources.count), Failed: \(failedResources.count), Skipped: \(skippedResources.count)")
            }, completionHandler: { skippedResources, failedResources, completedResources in
                if failedResources.isEmpty {
                    // All images downloaded successfully
                    completion(true)
                } else {
                    // Some images failed to download
                    completion(false)
                }
            })

            prefetcher.maxConcurrentDownloads = urls.count
            prefetcher.start()
        }
    }

Reproduce

[The steps to reproduce this issue. What is the url you were trying to load, where did you put your code, etc.]

Other Comment

I can see in the ImagePrefetcher() class, retry startegy is not assigned to the manager

    init(sources: [Source], options: KingfisherOptionsInfo?) {
        var options = KingfisherParsedOptionsInfo(options)
        prefetchSources = sources
        pendingSources = ArraySlice(sources)

        // We want all callbacks from our prefetch queue, so we should ignore the callback queue in options.
        // Add our own callback dispatch queue to make sure all internal callbacks are
        // coming back in our expected queue.
        options.callbackQueue = .dispatch(prefetchQueue)
        optionsInfo = options

        let cache = optionsInfo.targetCache ?? .default
        let downloader = optionsInfo.downloader ?? .default
        manager = KingfisherManager(downloader: downloader, cache: cache)
}
@Adobels
Copy link

Adobels commented Nov 11, 2024

It looks like the retry strategy defined in KingfisherOptionsInfo is not utilized by ImagePrefetcher, as it is currently only used by KingfisherManager.shared.retrieveImage, and UIImageView().kf.setImage.

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

2 participants