diff options
| author | Fuwn <[email protected]> | 2025-07-02 06:24:25 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-07-02 06:24:25 -0700 |
| commit | 28b263dbf1fe08aaa491d6da10aa7be5fe4feca9 (patch) | |
| tree | 621f8a17af7266888b0417d4781a56ace145dd43 /Sora/Data/ImageCacheManager.swift | |
| parent | feat: Development commit (diff) | |
| download | sora-testing-28b263dbf1fe08aaa491d6da10aa7be5fe4feca9.tar.xz sora-testing-28b263dbf1fe08aaa491d6da10aa7be5fe4feca9.zip | |
feat: Development commit
Diffstat (limited to 'Sora/Data/ImageCacheManager.swift')
| -rw-r--r-- | Sora/Data/ImageCacheManager.swift | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/Sora/Data/ImageCacheManager.swift b/Sora/Data/ImageCacheManager.swift index 5da8614..e789b74 100644 --- a/Sora/Data/ImageCacheManager.swift +++ b/Sora/Data/ImageCacheManager.swift @@ -13,22 +13,26 @@ final class ImageCacheManager { .appendingPathComponent("SoraImageCache", isDirectory: true) ) private var cancellables = Set<AnyCancellable>() + private let downloadQueue = OperationQueue() // MARK: - Initialisation private init() { URLCache.shared = cache + downloadQueue.maxConcurrentOperationCount = 5 } // MARK: - Public Methods func preloadImages(_ urls: [URL]) { urls.forEach { url in - URLSession.shared.dataTaskPublisher(for: url) - .map { CachedURLResponse(response: $0.response, data: $0.data) } - .sink( - receiveCompletion: { _ in () }, - receiveValue: { [cache] in cache.storeCachedResponse($0, for: URLRequest(url: url)) } - ) - .store(in: &cancellables) + downloadQueue.addOperation { + URLSession.shared.dataTaskPublisher(for: url) + .map { CachedURLResponse(response: $0.response, data: $0.data) } + .sink( + receiveCompletion: { _ in () }, + receiveValue: { [self] in cache.storeCachedResponse($0, for: URLRequest(url: url)) } + ) + .store(in: &self.cancellables) + } } } } |