This commit is contained in:
sunkaixuan
2017-09-28 16:21:46 +08:00
parent 09a98fad82
commit 7172e67d5f
11 changed files with 16 additions and 39 deletions

View File

@@ -11,7 +11,7 @@ namespace SqlSugar
{
Type type = typeof(T);
string key = "DataReaderToList." + fields + context.CurrentConnectionConfig.DbType + type.FullName;
IDataReaderEntityBuilder<T> entytyList = context.Utilities.GetCacheInstance().GetOrCreate(key, () =>
IDataReaderEntityBuilder<T> entytyList = context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(key, () =>
{
var cacheResult = new IDataReaderEntityBuilder<T>(context, dataReader).CreateBuilder(type);
return cacheResult;

View File

@@ -41,7 +41,7 @@ namespace SqlSugar
{
string cacheKey = "DbMaintenanceProvider.GetIsIdentities" + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
cacheKey = GetCacheKey(cacheKey);
return this.Context.Utilities.GetCacheInstance().GetOrCreate(cacheKey,() =>
return this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey,() =>
{
var result = GetColumnInfosByTableName(tableName).Where(it => it.IsIdentity).ToList();
return result.Select(it => it.DbColumnName).ToList();
@@ -51,7 +51,7 @@ namespace SqlSugar
{
string cacheKey = "DbMaintenanceProvider.GetPrimaries" + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
cacheKey = GetCacheKey(cacheKey);
return this.Context.Utilities.GetCacheInstance().GetOrCreate(cacheKey,() =>
return this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey,() =>
{
var result = GetColumnInfosByTableName(tableName).Where(it => it.IsPrimarykey).ToList();
return result.Select(it => it.DbColumnName).ToList();
@@ -206,7 +206,7 @@ namespace SqlSugar
#region Private
private List<T> GetListOrCache<T>(string cacheKey, string sql)
{
return this.Context.Utilities.GetCacheInstance().GetOrCreate(cacheKey,
return this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey,
() =>
{
var isEnableLogEvent = this.Context.Ado.IsEnableLogEvent;

View File

@@ -18,7 +18,7 @@ namespace SqlSugar
public EntityInfo GetEntityInfo(Type type)
{
string cacheKey = "GetEntityInfo" + type.FullName;
return this.Context.Utilities.GetCacheInstance().GetOrCreate(cacheKey,
return this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey,
() =>
{
EntityInfo result = new EntityInfo();

View File

@@ -263,9 +263,9 @@ namespace SqlSugar
#endregion
#region Cache
public ICacheService GetCacheInstance()
public ICacheService GetReflectionInoCacheInstance()
{
return ReflectionInoCache.GetInstance();
return InstanceFactory.GetReflectionInoCacheInstance();
}
public void RemoveCacheAll()

View File

@@ -356,13 +356,13 @@ namespace SqlSugar
#endregion
#region Services
public static ICacheService GetCacheInstance()
public static ICacheService GetReflectionInoCacheInstance()
{
return ReflectionInoCache.GetInstance();
return DefaultServices.ReflectionInoCache;
}
public static ISerializeService GetSerializeInstance()
{
return SerializeService.GetInstance();
return DefaultServices.Serialize;
}
#endregion
}

View File

@@ -98,7 +98,7 @@ namespace SqlSugar
public void InitMppingInfo(Type type)
{
string cacheKey = "Context.InitAttributeMappingTables" + type.FullName;
var entityInfo = this.Context.Utilities.GetCacheInstance().GetOrCreate<EntityInfo>(cacheKey,
var entityInfo = this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate<EntityInfo>(cacheKey,
() =>
{
var reval = this.Context.EntityMaintenance.GetEntityInfo(type);

View File

@@ -8,18 +8,6 @@ namespace SqlSugar
{
public class ReflectionInoCache : ICacheService
{
private static ReflectionInoCache _instance = null;
private static readonly object _instanceLock = new object();
public static ReflectionInoCache GetInstance()
{
if (_instance == null)
lock (_instanceLock)
if (_instance == null)
{
_instance = new ReflectionInoCache();
}
return _instance;
}
public void Add<V>(string key, V value)
{
ReflectionInoCache<V>.GetInstance().Add(key,value);

View File

@@ -8,17 +8,6 @@ namespace SqlSugar
{
public class SerializeService:ISerializeService
{
private static SerializeService _instance = null;
private static readonly object _instanceLock = new object();
public static SerializeService GetInstance() {
if (_instance == null)
lock (_instanceLock)
if (_instance == null)
{
_instance = new SerializeService();
}
return _instance;
}
public string SerializeObject(object value)
{
return JsonConvert.SerializeObject(value);

View File

@@ -18,7 +18,7 @@ namespace SqlSugar
T TranslateCopy<T>(T sourceObject);
SqlSugarClient CopyContext(SqlSugarClient context, bool isCopyEvents = false);
dynamic DataTableToDynamic(DataTable table);
ICacheService GetCacheInstance();
ICacheService GetReflectionInoCacheInstance();
void RemoveCacheAll();
void RemoveCacheAll<T>();
void RemoveCache<T>(string key);

View File

@@ -170,7 +170,7 @@ namespace SqlSugar
{
string cacheKey = "DbMaintenanceProvider.GetColumnInfosByTableName." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
cacheKey = GetCacheKey(cacheKey);
return this.Context.Utilities.GetCacheInstance().GetOrCreate(cacheKey,
return this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey,
() =>
{
string sql = "select * from " + tableName + " WHERE 1=2 ";
@@ -207,7 +207,7 @@ namespace SqlSugar
{
string cacheKey = "DbMaintenanceProvider.GetPrimaryKeyByTableNames." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
cacheKey = GetCacheKey(cacheKey);
return this.Context.Utilities.GetCacheInstance().GetOrCreate(cacheKey,
return this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey,
() =>
{
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;

View File

@@ -168,7 +168,7 @@ namespace SqlSugar
{
string cacheKey = "DbMaintenanceProvider.GetColumnInfosByTableName." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
cacheKey = GetCacheKey(cacheKey);
return this.Context.Utilities.GetCacheInstance().GetOrCreate(cacheKey,
return this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey,
() =>
{
string sql = "select * from " + tableName + " limit 0,1";
@@ -256,7 +256,7 @@ namespace SqlSugar
}
private List<T> GetListOrCache<T>(string cacheKey, string sql)
{
return this.Context.Utilities.GetCacheInstance().GetOrCreate(cacheKey,
return this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey,
() =>
{
var isEnableLogEvent = this.Context.Ado.IsEnableLogEvent;