This commit is contained in:
xuejiaming 2022-10-18 10:51:22 +08:00
parent 61f76b7b19
commit f09306530b
4 changed files with 22 additions and 24 deletions

View File

@ -57,15 +57,14 @@ namespace ShardingCore.EFCores
}
int waitSeconds = 3;
if (context is IShardingModelCacheOption shardingModelCacheOption)
{
waitSeconds = shardingModelCacheOption.GetModelCacheLockObjectSeconds();
}
var cacheKey = Dependencies.ModelCacheKeyFactory.Create(context);
if (!_models.TryGetValue(cacheKey, out var model))
{
if (context is IShardingModelCacheOption shardingModelCacheOption)
{
waitSeconds = shardingModelCacheOption.GetModelCacheLockObjectSeconds();
}
var acquire = Monitor.TryEnter(_syncObject, TimeSpan.FromSeconds(waitSeconds));
if (!acquire)
{

View File

@ -67,16 +67,16 @@ namespace ShardingCore.EFCores
priority = CacheItemPriority.Normal;
}
}
if (context is IShardingModelCacheOption shardingModelCacheOption)
{
priority = shardingModelCacheOption.GetModelCachePriority();
size = shardingModelCacheOption.GetModelCacheEntrySize();
waitSeconds = shardingModelCacheOption.GetModelCacheLockObjectSeconds();
}
var cache = Dependencies.MemoryCache;
var cacheKey = Dependencies.ModelCacheKeyFactory.Create(context);
if (!cache.TryGetValue(cacheKey, out IModel model))
{
if (context is IShardingModelCacheOption shardingModelCacheOption)
{
priority = shardingModelCacheOption.GetModelCachePriority();
size = shardingModelCacheOption.GetModelCacheEntrySize();
waitSeconds = shardingModelCacheOption.GetModelCacheLockObjectSeconds();
}
// Make sure OnModelCreating really only gets called once, since it may not be thread safe.
var acquire = Monitor.TryEnter(_syncObject, TimeSpan.FromSeconds(waitSeconds));

View File

@ -83,16 +83,16 @@ namespace ShardingCore.EFCores
priority = CacheItemPriority.Normal;
}
}
if (context is IShardingModelCacheOption shardingModelCacheOption)
{
priority = shardingModelCacheOption.GetModelCachePriority();
size = shardingModelCacheOption.GetModelCacheEntrySize();
waitSeconds = shardingModelCacheOption.GetModelCacheLockObjectSeconds();
}
var cache = Dependencies.MemoryCache;
var cacheKey = Dependencies.ModelCacheKeyFactory.Create(context);
if (!cache.TryGetValue(cacheKey, out IModel model))
{
if (context is IShardingModelCacheOption shardingModelCacheOption)
{
priority = shardingModelCacheOption.GetModelCachePriority();
size = shardingModelCacheOption.GetModelCacheEntrySize();
waitSeconds = shardingModelCacheOption.GetModelCacheLockObjectSeconds();
}
// Make sure OnModelCreating really only gets called once, since it may not be thread safe.
var acquire = Monitor.TryEnter(_syncObject, TimeSpan.FromSeconds(waitSeconds));
if (!acquire)

View File

@ -98,17 +98,16 @@ namespace ShardingCore.EFCores
priority = CacheItemPriority.Normal;
}
}
if (context is IShardingModelCacheOption shardingModelCacheOption)
{
priority = shardingModelCacheOption.GetModelCachePriority();
size = shardingModelCacheOption.GetModelCacheEntrySize();
waitSeconds = shardingModelCacheOption.GetModelCacheLockObjectSeconds();
}
var cache = Dependencies.MemoryCache;
var cacheKey = Dependencies.ModelCacheKeyFactory.Create(context, designTime);
if (!cache.TryGetValue(cacheKey, out IModel model))
{
if (context is IShardingModelCacheOption shardingModelCacheOption)
{
priority = shardingModelCacheOption.GetModelCachePriority();
size = shardingModelCacheOption.GetModelCacheEntrySize();
waitSeconds = shardingModelCacheOption.GetModelCacheLockObjectSeconds();
}
// Make sure OnModelCreating really only gets called once, since it may not be thread safe.
var acquire = Monitor.TryEnter(_syncObject, TimeSpan.FromSeconds(waitSeconds));
if (!acquire)