summaryrefslogtreecommitdiff
path: root/DomainDig/RDAPService.swift
diff options
context:
space:
mode:
Diffstat (limited to 'DomainDig/RDAPService.swift')
-rw-r--r--DomainDig/RDAPService.swift31
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")