diff --git a/src/ImageSharpCommunity.Providers.Remote/Helpers.cs b/src/ImageSharpCommunity.Providers.Remote/Helpers.cs index f911c3a..d01a8a2 100644 --- a/src/ImageSharpCommunity.Providers.Remote/Helpers.cs +++ b/src/ImageSharpCommunity.Providers.Remote/Helpers.cs @@ -1,3 +1,4 @@ +using System.Collections.Concurrent; using System.Text; using System.Text.RegularExpressions; using ImageSharpCommunity.Providers.Remote.Configuration; @@ -10,7 +11,7 @@ namespace ImageSharpCommunity.Providers.Remote; public static class Helpers { - private static Dictionary HttpClients { get; } = new Dictionary(); + private static ConcurrentDictionary HttpClients { get; } = new ConcurrentDictionary(); /// /// Gets the remote URL for a given path, based on the specified options. @@ -35,7 +36,7 @@ public static HttpClient GetRemoteImageProviderHttpClient(this IHttpClientFactor httpClient.Timeout = TimeSpan.FromMilliseconds(setting.Timeout); httpClient.MaxResponseContentBufferSize = setting.MaxBytes; - HttpClients.TryAdd(setting.ClientDictionaryKey, httpClient); + HttpClients.AddOrUpdate(setting.ClientDictionaryKey, httpClient, (_, _) => httpClient); return httpClient; }