Replace Dictionary with ConcurrentDictionary (#2503)

This commit is contained in:
Abdelrahman El Kinani 2021-11-19 21:56:58 +02:00 committed by GitHub
parent ce87ded827
commit 76bb8a9eb6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -95,7 +96,7 @@ namespace Elsa.Persistence.InMemory
return dictionary.Values.AsQueryable().FirstOrDefault(specification.ToExpression());
}
private async Task<IDictionary<string, T>> GetDictionaryAsync() => await MemoryCache.GetOrCreateAsync(CacheKey, _ => Task.FromResult(new Dictionary<string, T>()));
private async Task<IDictionary<string, T>> GetDictionaryAsync() => await MemoryCache.GetOrCreateAsync(CacheKey, _ => Task.FromResult(new ConcurrentDictionary<string, T>()));
private void SetDictionary(IDictionary<string, T> dictionary) => MemoryCache.Set(CacheKey, dictionary);
}
}