diff --git a/Libraries/SPTarkov.Server.Core/Services/BundleHashCacheService.cs b/Libraries/SPTarkov.Server.Core/Services/BundleHashCacheService.cs index 745add9d..fa96eeaa 100644 --- a/Libraries/SPTarkov.Server.Core/Services/BundleHashCacheService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/BundleHashCacheService.cs @@ -1,5 +1,6 @@ using SPTarkov.DI.Annotations; using SPTarkov.Server.Core.Models.Utils; +using System.Collections.Concurrent; using SPTarkov.Server.Core.Utils; namespace SPTarkov.Server.Core.Services; @@ -9,7 +10,7 @@ public class BundleHashCacheService(ISptLogger logger, J { protected const string _bundleHashCachePath = "./user/cache/"; protected const string _cacheName = "bundleHashCache.json"; - protected Dictionary _bundleHashes = []; + protected ConcurrentDictionary _bundleHashes = []; private readonly SemaphoreSlim _writeLock = new(1, 1); public async Task HydrateCache() @@ -27,7 +28,7 @@ public class BundleHashCacheService(ISptLogger logger, J return; } - _bundleHashes = await jsonUtil.DeserializeFromFileAsync>(fullCachePath) ?? []; + _bundleHashes = await jsonUtil.DeserializeFromFileAsync>(fullCachePath) ?? []; } public async Task WriteCache() @@ -63,7 +64,7 @@ public class BundleHashCacheService(ISptLogger logger, J protected async Task StoreValue(string bundlePath, uint hash) { - _bundleHashes[bundlePath] = hash; + _bundleHashes.TryAdd(bundlePath, hash); logger.Debug($"Bundle: {bundlePath} hash stored in cache"); }