Skip to content

Commit 7d5fa41

Browse files
committed
Use ConcurrentDictionary for storing HttpClients
1 parent 53a6c0b commit 7d5fa41

File tree

1 file changed

+3
-2
lines changed
  • src/ImageSharpCommunity.Providers.Remote

1 file changed

+3
-2
lines changed

src/ImageSharpCommunity.Providers.Remote/Helpers.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Collections.Concurrent;
12
using System.Text;
23
using System.Text.RegularExpressions;
34
using ImageSharpCommunity.Providers.Remote.Configuration;
@@ -10,7 +11,7 @@ namespace ImageSharpCommunity.Providers.Remote;
1011

1112
public static class Helpers
1213
{
13-
private static Dictionary<string, HttpClient> HttpClients { get; } = new Dictionary<string, HttpClient>();
14+
private static ConcurrentDictionary<string, HttpClient> HttpClients { get; } = new ConcurrentDictionary<string, HttpClient>();
1415

1516
/// <summary>
1617
/// Gets the remote URL for a given path, based on the specified options.
@@ -35,7 +36,7 @@ public static HttpClient GetRemoteImageProviderHttpClient(this IHttpClientFactor
3536
httpClient.Timeout = TimeSpan.FromMilliseconds(setting.Timeout);
3637
httpClient.MaxResponseContentBufferSize = setting.MaxBytes;
3738

38-
HttpClients.TryAdd(setting.ClientDictionaryKey, httpClient);
39+
HttpClients.AddOrUpdate(setting.ClientDictionaryKey, httpClient, (_, _) => httpClient);
3940

4041
return httpClient;
4142
}

0 commit comments

Comments
 (0)