public static void ConfigureOurServices()

in CachingProxy/src/Program.cs [63:82]


  public static void ConfigureOurServices(IServiceCollection services)
  {
    services
      .AddMemoryCache()
      .AddSingleton<CachingProxyMetrics>()
      .AddSingleton<ResponseCache>()
      .AddHttpClient<ProxyHttpClient>((provider, client) =>
      {
        var config = provider.GetRequiredService<IOptions<CachingProxyConfig>>().Value;
        client.Timeout = TimeSpan.FromSeconds(config.RequestTimeoutSec);
      })
      .UseSocketsHttpHandler((handler, _) =>
      {
        // force reconnection (and DNS re-resolve) every two minutes
        handler.PooledConnectionLifetime = TimeSpan.FromMinutes(2);
        handler.UseCookies = false;
      })
      .AddTransientHttpErrorPolicy(policyBuilder => policyBuilder.WaitAndRetryAsync(
        4, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt - 1))));
  }