summaryrefslogtreecommitdiff
path: root/Sora/Data/ImageCacheManager.swift
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-07-02 06:24:25 -0700
committerFuwn <[email protected]>2025-07-02 06:24:25 -0700
commit28b263dbf1fe08aaa491d6da10aa7be5fe4feca9 (patch)
tree621f8a17af7266888b0417d4781a56ace145dd43 /Sora/Data/ImageCacheManager.swift
parentfeat: Development commit (diff)
downloadsora-testing-28b263dbf1fe08aaa491d6da10aa7be5fe4feca9.tar.xz
sora-testing-28b263dbf1fe08aaa491d6da10aa7be5fe4feca9.zip
feat: Development commit
Diffstat (limited to 'Sora/Data/ImageCacheManager.swift')
-rw-r--r--Sora/Data/ImageCacheManager.swift18
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)
+ }
}
}
}