mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 10:08:19 +08:00
Code optimization
This commit is contained in:
@@ -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];
|
||||
|
@@ -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];
|
||||
|
@@ -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];
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -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];
|
||||
|
@@ -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];
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user