Browse Source

非超时异常缓存

老九 3 years ago
parent
commit
059907faf5
1 changed files with 2 additions and 3 deletions
  1. 2 3
      FastGithub.DomainResolve/DnsClient.cs

+ 2 - 3
FastGithub.DomainResolve/DnsClient.cs

@@ -124,8 +124,7 @@ namespace FastGithub.DomainResolve
                 }
 
                 var result = await this.LookupCoreAsync(dns, endPoint, fastSort, cancellationToken);
-                this.dnsCache.Set(key, result.Addresses, result.TimeToLive);
-                return result.Addresses;
+                return this.dnsCache.Set(key, result.Addresses, result.TimeToLive);
             }
             catch (OperationCanceledException)
             {
@@ -135,7 +134,7 @@ namespace FastGithub.DomainResolve
             catch (Exception ex)
             {
                 this.logger.LogWarning($"dns://{dns}无法解析{endPoint.Host}:{ex.Message}");
-                return Array.Empty<IPAddress>();
+                return this.dnsCache.Set(key, Array.Empty<IPAddress>(), this.maxTimeToLive);
             }
             finally
             {