Code optimization

This commit is contained in:
sunkaixuan
2017-09-28 13:12:22 +08:00
parent 15ea065e0c
commit 781090b7d9
7 changed files with 11 additions and 20 deletions

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<List<string>>().Func(cacheKey,
return this.Context.Utilities.GetCacheInstance<List<string>>().GetOrCreate(cacheKey,
(cm, key) =>
{
return cm[cacheKey];
@@ -56,7 +56,7 @@ namespace SqlSugar
{
string cacheKey = "DbMaintenanceProvider.GetPrimaries" + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
cacheKey = GetCacheKey(cacheKey);
return this.Context.Utilities.GetCacheInstance<List<string>>().Func(cacheKey,
return this.Context.Utilities.GetCacheInstance<List<string>>().GetOrCreate(cacheKey,
(cm, key) =>
{
return cm[cacheKey];
@@ -216,7 +216,7 @@ namespace SqlSugar
#region Private
private List<T> GetListOrCache<T>(string cacheKey, string sql)
{
return this.Context.Utilities.GetCacheInstance<List<T>>().Func(cacheKey,
return this.Context.Utilities.GetCacheInstance<List<T>>().GetOrCreate(cacheKey,
(cm, key) =>
{
return cm[cacheKey];

View File

@@ -18,7 +18,7 @@ namespace SqlSugar
public EntityInfo GetEntityInfo(Type type)
{
string cacheKey = "GetEntityInfo" + type.FullName;
return this.Context.Utilities.GetCacheInstance<EntityInfo>().Func(cacheKey,
return this.Context.Utilities.GetCacheInstance<EntityInfo>().GetOrCreate(cacheKey,
(cm, key) =>
{
return cm[cacheKey];

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<EntityInfo>().Func(cacheKey,
var entityInfo = this.Context.Utilities.GetCacheInstance<EntityInfo>().GetOrCreate(cacheKey,
(cm, key) =>
{
var cacheInfo = cm[key];

View File

@@ -12,7 +12,6 @@ namespace SqlSugar
V Get(string key);
IEnumerable<string> GetAllKey();
void Remove(string key);
V Func(string cacheKey, Func<ICacheManager<V>, string, V> successAction, Func<ICacheManager<V>, string, V> errorAction);
void Action(string cacheKey, Action<ICacheManager<V>, string> successAction, Func<ICacheManager<V>, string, V> errorAction);
V GetOrCreate(string cacheKey, Func<ICacheManager<V>, string, V> successAction, Func<ICacheManager<V>, string, V> errorAction);
}
}

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<List<DbColumnInfo>>().Func(cacheKey,
return this.Context.Utilities.GetCacheInstance<List<DbColumnInfo>>().GetOrCreate(cacheKey,
(cm, key) =>
{
return cm[cacheKey];
@@ -211,7 +211,7 @@ namespace SqlSugar
{
string cacheKey = "DbMaintenanceProvider.GetPrimaryKeyByTableNames." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
cacheKey = GetCacheKey(cacheKey);
return this.Context.Utilities.GetCacheInstance<List<string>>().Func(cacheKey,
return this.Context.Utilities.GetCacheInstance<List<string>>().GetOrCreate(cacheKey,
(cm, key) =>
{
return cm[cacheKey];

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<List<DbColumnInfo>>().Func(cacheKey,
return this.Context.Utilities.GetCacheInstance<List<DbColumnInfo>>().GetOrCreate(cacheKey,
(cm, key) =>
{
return cm[cacheKey];
@@ -260,7 +260,7 @@ namespace SqlSugar
}
private List<T> GetListOrCache<T>(string cacheKey, string sql)
{
return this.Context.Utilities.GetCacheInstance<List<T>>().Func(cacheKey,
return this.Context.Utilities.GetCacheInstance<List<T>>().GetOrCreate(cacheKey,
(cm, key) =>
{
return cm[cacheKey];

View File

@@ -76,15 +76,7 @@ namespace SqlSugar
return this.InstanceCache.Keys;
}
public void Action(string cacheKey, Action<ICacheManager<V>, string> successAction, Func<ICacheManager<V>, string, V> errorAction)
{
if (this.ContainsKey(cacheKey)) successAction(this, cacheKey);
else
{
this.Add(cacheKey, errorAction(this, cacheKey));
}
}
public V Func(string cacheKey, Func<ICacheManager<V>, string, V> successAction, Func<ICacheManager<V>, string, V> errorAction)
public V GetOrCreate(string cacheKey, Func<ICacheManager<V>, string, V> successAction, Func<ICacheManager<V>, string, V> errorAction)
{
var cm = CacheManager<V>.GetInstance();
if (cm.ContainsKey(cacheKey)) return successAction(cm, cacheKey);