解决多实例情况下的静态集合缓存问题

This commit is contained in:
hyzx86 2023-09-27 00:54:43 +08:00
parent 922f645249
commit 3c7d67fcc2

View File

@ -19,10 +19,24 @@ namespace FreeSql.Internal
{
public class Utils
{
/// <summary>
/// 用于解决多实例情况下的静态集合缓存问题
/// </summary>
public static Func<ConcurrentDictionary<DataType, ConcurrentDictionary<Type, TableInfo>>> ChacheTableEntityFactory = null;
private static ConcurrentDictionary<DataType, ConcurrentDictionary<Type, TableInfo>> __cacheGetTableByEntity;
public static ConcurrentDictionary<DataType, ConcurrentDictionary<Type, TableInfo>> _cacheGetTableByEntity
{
get; set;
} = new ConcurrentDictionary<DataType, ConcurrentDictionary<Type, TableInfo>>();
get
{
if (ChacheTableEntityFactory != null)
{
return ChacheTableEntityFactory.Invoke();
}
__cacheGetTableByEntity ??= new ConcurrentDictionary<DataType, ConcurrentDictionary<Type, TableInfo>>();
return __cacheGetTableByEntity;
}
}
internal static void RemoveTableByEntity(Type entity, CommonUtils common)
{
if (entity.IsAnonymousType() ||