同步操作将从 Gitee 极速下载/fastgithub 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
using FastGithub.Configuration;using FastGithub.DomainResolve;using System;using System.Collections.Concurrent;namespace FastGithub.Http{/// <summary>/// HttpClient工厂/// </summary>sealed class HttpClientFactory : IHttpClientFactory{private readonly IDomainResolver domainResolver;/// <summary>/// 首次生命周期/// </summary>private readonly TimeSpan firstLiftTime = TimeSpan.FromSeconds(10d);/// <summary>/// 非首次生命周期/// </summary>private readonly TimeSpan nextLifeTime = TimeSpan.FromSeconds(100d);/// <summary>/// LifetimeHttpHandler清理器/// </summary>private readonly LifetimeHttpHandlerCleaner httpHandlerCleaner = new();/// <summary>/// LazyOf(LifetimeHttpHandler)缓存/// </summary>private readonly ConcurrentDictionary<LifeTimeKey, Lazy<LifetimeHttpHandler>> httpHandlerLazyCache = new();/// <summary>/// HttpClient工厂/// </summary>/// <param name="domainResolver"></param>public HttpClientFactory(IDomainResolver domainResolver){this.domainResolver = domainResolver;}/// <summary>/// 创建httpClient/// </summary>/// <param name="domain"></param>/// <param name="domainConfig"></param>/// <returns></returns>public HttpClient CreateHttpClient(string domain, DomainConfig domainConfig){var lifeTimeKey = new LifeTimeKey(domain, domainConfig);var lifetimeHttpHandler = this.httpHandlerLazyCache.GetOrAdd(lifeTimeKey, CreateLifetimeHttpHandlerLazy).Value;return new HttpClient(lifetimeHttpHandler, disposeHandler: false);Lazy<LifetimeHttpHandler> CreateLifetimeHttpHandlerLazy(LifeTimeKey lifeTimeKey){return new Lazy<LifetimeHttpHandler>(() => this.CreateLifetimeHttpHandler(lifeTimeKey, this.firstLiftTime), true);}}/// <summary>/// 创建LifetimeHttpHandler/// </summary>/// <param name="lifeTimeKey"></param>/// <param name="lifeTime"></param>/// <returns></returns>private LifetimeHttpHandler CreateLifetimeHttpHandler(LifeTimeKey lifeTimeKey, TimeSpan lifeTime){return new LifetimeHttpHandler(this.domainResolver, lifeTimeKey, lifeTime, this.OnLifetimeHttpHandlerDeactivate);}/// <summary>/// 当有httpHandler失效时/// </summary>/// <param name="lifetimeHttpHandler">httpHandler</param>private void OnLifetimeHttpHandlerDeactivate(LifetimeHttpHandler lifetimeHttpHandler){var lifeTimeKey = lifetimeHttpHandler.LifeTimeKey;this.httpHandlerLazyCache[lifeTimeKey] = CreateLifetimeHttpHandlerLazy(lifeTimeKey);this.httpHandlerCleaner.Add(lifetimeHttpHandler);Lazy<LifetimeHttpHandler> CreateLifetimeHttpHandlerLazy(LifeTimeKey lifeTimeKey){return new Lazy<LifetimeHttpHandler>(() => this.CreateLifetimeHttpHandler(lifeTimeKey, this.nextLifeTime), true);}}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。