From 18981505eff1d279c68074fd2f73ab9403858e3f Mon Sep 17 00:00:00 2001 From: Cyrille DUPUYDAUBY Date: Tue, 5 Nov 2024 15:54:19 +0100 Subject: [PATCH] fix: use concurrent dictionnary for resource cache --- .../Initialisation/EmbeddedResourcesGenerator.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Stryker.Core/Stryker.Core/Initialisation/EmbeddedResourcesGenerator.cs b/src/Stryker.Core/Stryker.Core/Initialisation/EmbeddedResourcesGenerator.cs index 895955d13..6085b719c 100644 --- a/src/Stryker.Core/Stryker.Core/Initialisation/EmbeddedResourcesGenerator.cs +++ b/src/Stryker.Core/Stryker.Core/Initialisation/EmbeddedResourcesGenerator.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Collections.Concurrent; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; @@ -16,7 +17,7 @@ namespace Stryker.Core.Initialisation; [ExcludeFromCodeCoverage] public static class EmbeddedResourcesGenerator { - private static readonly Dictionary> _resourceDescriptions = new(); + private static readonly ConcurrentDictionary> _resourceDescriptions = new(); public static void ResetCache() { @@ -30,7 +31,7 @@ public static IEnumerable GetManifestResources(string assem using var module = LoadModule(assemblyPath); if (module is not null) { - _resourceDescriptions.Add(projectFilePath, ReadResourceDescriptionsFromModule(module).ToList()); + _resourceDescriptions.TryAdd(projectFilePath, ReadResourceDescriptionsFromModule(module).ToList()); } // Failed to load some or all resources from module, generate missing resources from disk @@ -43,7 +44,7 @@ public static IEnumerable GetManifestResources(string assem // Failed to load module, generate all resources from disk if (module is null) { - _resourceDescriptions.Add(projectFilePath, GenerateManifestResources(projectFilePath, rootNamespace, embeddedResources)); + _resourceDescriptions.TryAdd(projectFilePath, GenerateManifestResources(projectFilePath, rootNamespace, embeddedResources)); } }