From a5d79b40db91d497b4eac5339a5b253e5d96c733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=9B=BD=E4=BC=9F?= <366193849@qq.com> Date: Wed, 24 Nov 2021 15:50:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AA=E4=BF=9D=E7=95=99=20socket=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Directory.Build.props | 2 +- FastGithub.DomainResolve/DnsClient.cs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 7effae0..d1c9920 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 2.1.0 + 2.1.1 enable net6.0 true diff --git a/FastGithub.DomainResolve/DnsClient.cs b/FastGithub.DomainResolve/DnsClient.cs index c87478f..2301373 100644 --- a/FastGithub.DomainResolve/DnsClient.cs +++ b/FastGithub.DomainResolve/DnsClient.cs @@ -31,7 +31,7 @@ namespace FastGithub.DomainResolve private readonly ILogger logger; private readonly ConcurrentDictionary semaphoreSlims = new(); - private readonly IMemoryCache dnsCache = new MemoryCache(Options.Create(new MemoryCacheOptions())); + private readonly IMemoryCache dnsLookupCache = new MemoryCache(Options.Create(new MemoryCacheOptions())); private readonly TimeSpan minTimeToLive = TimeSpan.FromSeconds(30d); private readonly TimeSpan maxTimeToLive = TimeSpan.FromMinutes(10d); @@ -118,13 +118,13 @@ namespace FastGithub.DomainResolve try { - if (this.dnsCache.TryGetValue>(key, out var value)) + if (this.dnsLookupCache.TryGetValue>(key, out var value)) { return value; } var result = await this.LookupCoreAsync(dns, endPoint, fastSort, cancellationToken); - return this.dnsCache.Set(key, result.Addresses, result.TimeToLive); + return this.dnsLookupCache.Set(key, result.Addresses, result.TimeToLive); } catch (OperationCanceledException) { @@ -133,12 +133,12 @@ namespace FastGithub.DomainResolve catch (SocketException ex) { this.logger.LogWarning($"{endPoint.Host}@{dns}:{ex.Message}"); - return this.dnsCache.Set(key, Array.Empty(), this.minTimeToLive); + return this.dnsLookupCache.Set(key, Array.Empty(), this.minTimeToLive); } catch (Exception ex) { this.logger.LogWarning($"{endPoint.Host}@{dns}:{ex.Message}"); - return this.dnsCache.Set(key, Array.Empty(), this.minTimeToLive); + return Array.Empty(); } finally {