Skip to content

Commit

Permalink
fix(embedded resources): Use concurrent dictionnary for resource cache (
Browse files Browse the repository at this point in the history
#3095)

fix: use concurrent dictionnary for resource cache
  • Loading branch information
dupdob authored Nov 8, 2024
1 parent 0aafb7f commit b3f0ef0
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
Expand All @@ -16,7 +17,7 @@ namespace Stryker.Core.Initialisation;
[ExcludeFromCodeCoverage]
public static class EmbeddedResourcesGenerator
{
private static readonly Dictionary<string, IEnumerable<(ResourceDescription description, object context)>> _resourceDescriptions = new();
private static readonly ConcurrentDictionary<string, IEnumerable<(ResourceDescription description, object context)>> _resourceDescriptions = new();

public static void ResetCache()
{
Expand All @@ -30,7 +31,7 @@ public static IEnumerable<ResourceDescription> 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
Expand All @@ -43,7 +44,7 @@ public static IEnumerable<ResourceDescription> 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));
}
}

Expand Down

0 comments on commit b3f0ef0

Please sign in to comment.