只保留 socket异常缓存
This commit is contained in:
parent
aba0ea7c2f
commit
a5d79b40db
@ -1,6 +1,6 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<Version>2.1.0</Version>
|
||||
<Version>2.1.1</Version>
|
||||
<Nullable>enable</Nullable>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<IsWebConfigTransformDisabled>true</IsWebConfigTransformDisabled>
|
||||
|
||||
@ -31,7 +31,7 @@ namespace FastGithub.DomainResolve
|
||||
private readonly ILogger<DnsClient> logger;
|
||||
|
||||
private readonly ConcurrentDictionary<string, SemaphoreSlim> 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<IList<IPAddress>>(key, out var value))
|
||||
if (this.dnsLookupCache.TryGetValue<IList<IPAddress>>(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<IPAddress>(), this.minTimeToLive);
|
||||
return this.dnsLookupCache.Set(key, Array.Empty<IPAddress>(), this.minTimeToLive);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.logger.LogWarning($"{endPoint.Host}@{dns}:{ex.Message}");
|
||||
return this.dnsCache.Set(key, Array.Empty<IPAddress>(), this.minTimeToLive);
|
||||
return Array.Empty<IPAddress>();
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user