forked from ddrilling/AsbCloudServer
fix CacheDb. Make cache ConcurrentDictionary
This commit is contained in:
parent
589959c802
commit
0a3891a332
@ -9,8 +9,8 @@ namespace AsbCloudInfrastructure.Services.Cache
|
||||
|
||||
public class CacheDb
|
||||
{
|
||||
private readonly Dictionary<string, (DateTime, IEnumerable)> cache =
|
||||
new Dictionary<string, (DateTime, IEnumerable)>();
|
||||
private readonly ConcurrentDictionary<string, (DateTime, IEnumerable)> cache =
|
||||
new ConcurrentDictionary<string, (DateTime, IEnumerable)>();
|
||||
|
||||
private readonly TimeSpan obsolesenceTime = TimeSpan.FromMinutes(15);
|
||||
|
||||
@ -19,12 +19,11 @@ namespace AsbCloudInfrastructure.Services.Cache
|
||||
{
|
||||
var entityTypeName = typeof(TEntity).FullName;
|
||||
|
||||
if (!cache.ContainsKey(entityTypeName))
|
||||
cache[entityTypeName] = (DateTime.Now, new List<TEntity>());
|
||||
var cacheItem = cache.GetOrAdd(entityTypeName, (DateTime.Now, new List<TEntity>()));
|
||||
|
||||
bool isCachedDataObsolete = DateTime.Now - cache[entityTypeName].Item1 > obsolesenceTime;
|
||||
bool isCachedDataObsolete = DateTime.Now - cacheItem.Item1 > obsolesenceTime;
|
||||
|
||||
var tableCache = new CacheTable<TEntity>(context, cache[entityTypeName]);
|
||||
var tableCache = new CacheTable<TEntity>(context, cacheItem);
|
||||
|
||||
if (isCachedDataObsolete)
|
||||
tableCache.Refresh();
|
||||
|
Loading…
Reference in New Issue
Block a user