示例#1
0
        public HttpClient CreateClientWithProxy(IWebProxy webProxy)
        {
            var key = webProxy.GetHashCode();

            lock (this.cache)
            {
                if (this.cache.ContainsKey(key))
                {
                    return(this.cache[key]);
                }
                var result = this.httpClientFactory.CreateClientWithProxy(webProxy);
                this.cache.Add(key, result);
                return(result);
            }
        }
示例#2
0
 private HttpClient ProxiedClientFromCache(IWebProxy proxy)
 {
     lock (clients)
     {
         var result = this.clients.AddOrUpdate(
             key: proxy.GetHashCode().ToString(),
             addValueFactory: u =>
         {
             return(new HttpClientAndTimestamp()
             {
                 client = CreateProxiedClient(proxy),
                 lastFetchTimestamp = Stopwatch.GetTimestamp()
             });
         },
             updateValueFactory: (u, value) =>
         {
             return(value);
         }
             );
         result.lastFetchTimestamp = Stopwatch.GetTimestamp();
         CleanupHttpClientCache();
         return(result.client);
     }
 }