diff options
| author | Christian Cleberg <[email protected]> | 2026-04-21 23:21:19 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-04-21 23:21:19 -0500 |
| commit | 3846dc2f5dee69fc4ffbc052009a60e17d60e36b (patch) | |
| tree | 867dca9d45b87f318c1b368cd535c9c9fb53e29d /DomainDig/RDAPService.swift | |
| parent | e73d58ee5dd43eaeaaa717f7781cc22256df30f0 (diff) | |
| download | domain-dig-3846dc2f5dee69fc4ffbc052009a60e17d60e36b.tar.gz domain-dig-3846dc2f5dee69fc4ffbc052009a60e17d60e36b.tar.bz2 domain-dig-3846dc2f5dee69fc4ffbc052009a60e17d60e36b.zip | |
feat(v2.5.0): add caching, request deduplication, and performance improvements
Diffstat (limited to 'DomainDig/RDAPService.swift')
| -rw-r--r-- | DomainDig/RDAPService.swift | 31 |
1 files changed, 2 insertions, 29 deletions
diff --git a/DomainDig/RDAPService.swift b/DomainDig/RDAPService.swift index c38a140..3556624 100644 --- a/DomainDig/RDAPService.swift +++ b/DomainDig/RDAPService.swift @@ -5,7 +5,7 @@ enum RDAPService { let normalizedDomain = normalize(domain) guard !normalizedDomain.isEmpty else { return nil } - switch await cache.response(for: normalizedDomain) { + switch await fetchRDAPResponse(for: normalizedDomain) { case let .success(response): return response.isDomainRecord ? .registered : nil case .empty: @@ -21,7 +21,7 @@ enum RDAPService { return .empty("Unavailable") } - switch await cache.response(for: normalizedDomain) { + switch await fetchRDAPResponse(for: normalizedDomain) { case let .success(response): let ownership = DomainOwnership( registrar: response.registrarName, @@ -39,8 +39,6 @@ enum RDAPService { } } - private static let cache = RDAPCache() - private static func normalize(_ domain: String) -> String { domain .trimmingCharacters(in: .whitespacesAndNewlines) @@ -48,31 +46,6 @@ enum RDAPService { } } -private actor RDAPCache { - private var cachedResponses: [String: ServiceResult<RDAPDomainResponse>] = [:] - private var inFlightTasks: [String: Task<ServiceResult<RDAPDomainResponse>, Never>] = [:] - - func response(for domain: String) async -> ServiceResult<RDAPDomainResponse> { - if let cachedResponse = cachedResponses[domain] { - return cachedResponse - } - - if let inFlightTask = inFlightTasks[domain] { - return await inFlightTask.value - } - - let task = Task<ServiceResult<RDAPDomainResponse>, Never> { - await fetchRDAPResponse(for: domain) - } - inFlightTasks[domain] = task - - let result = await task.value - cachedResponses[domain] = result - inFlightTasks[domain] = nil - return result - } -} - private func fetchRDAPResponse(for domain: String) async -> ServiceResult<RDAPDomainResponse> { guard let url = URL(string: "https://rdap.org/domain/\(domain)") else { return .error("Unavailable") |
