summaryrefslogtreecommitdiff
path: root/Sora/Data/ImageCacheManager.swift
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-07-02 09:48:06 -0700
committerFuwn <[email protected]>2025-07-02 09:57:31 -0700
commit266d52f5c5afebde5a173ea5b4be071bb53d0cd4 (patch)
tree93d8a7317547eb42c432e1916473e6f1e1433131 /Sora/Data/ImageCacheManager.swift
parentfeat: Development commit (diff)
downloadsora-testing-266d52f5c5afebde5a173ea5b4be071bb53d0cd4.tar.xz
sora-testing-266d52f5c5afebde5a173ea5b4be071bb53d0cd4.zip
feat: Development commit
Diffstat (limited to 'Sora/Data/ImageCacheManager.swift')
-rw-r--r--Sora/Data/ImageCacheManager.swift20
1 files changed, 12 insertions, 8 deletions
diff --git a/Sora/Data/ImageCacheManager.swift b/Sora/Data/ImageCacheManager.swift
index e789b74..ed68c67 100644
--- a/Sora/Data/ImageCacheManager.swift
+++ b/Sora/Data/ImageCacheManager.swift
@@ -13,11 +13,13 @@ final class ImageCacheManager {
.appendingPathComponent("SoraImageCache", isDirectory: true)
)
private var cancellables = Set<AnyCancellable>()
+ private let cancellablesQueue = DispatchQueue(
+ label: "\(Bundle.main.bundleIdentifier!).ImageCacheManager.cancellablesQueue"
+ )
private let downloadQueue = OperationQueue()
// MARK: - Initialisation
private init() {
- URLCache.shared = cache
downloadQueue.maxConcurrentOperationCount = 5
}
@@ -25,13 +27,15 @@ final class ImageCacheManager {
func preloadImages(_ urls: [URL]) {
urls.forEach { url in
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)
+ self.cancellablesQueue.sync {
+ 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)
+ }
}
}
}