-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfileImageDataRepositoryImpl.swift
More file actions
39 lines (34 loc) · 1007 Bytes
/
Copy pathProfileImageDataRepositoryImpl.swift
File metadata and controls
39 lines (34 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// ProfileImageDataRepositoryImpl.swift
// DevLogData
//
// Created by opfic on 6/11/26.
//
import Foundation
import DevLogDomain
public final class ProfileImageDataRepositoryImpl: ProfileImageDataRepository {
private let service: ProfileImageDataService
private let store: MemoryCacheStore
public init(
service: ProfileImageDataService,
store: MemoryCacheStore
) {
self.service = service
self.store = store
}
public func fetchImageData(from url: URL) async throws -> Data {
do {
let data = try await service.fetchImageData(from: url)
store.setValue(data, forKey: Self.cacheKey(for: url))
return data
} catch {
if let data: Data = store.value(forKey: Self.cacheKey(for: url)) {
return data
}
throw error
}
}
private static func cacheKey(for url: URL) -> String {
"profileImageData:\(url.absoluteString)"
}
}