Support RemoveDataCache by likeString

This commit is contained in:
SUNKAIXUAN 2021-03-27 12:35:22 +08:00
parent 14820498f4
commit 6c85c49e4c
7 changed files with 48 additions and 1 deletions

View File

@ -238,7 +238,15 @@ namespace SqlSugar
};
return this;
}
public IDeleteable<T> RemoveDataCache(string likeString)
{
this.RemoveCacheFunc = () =>
{
var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService;
CacheSchemeMain.RemoveCache(cacheService, likeString);
};
return this;
}
public IDeleteable<T> In<PkType>(List<PkType> primaryKeyValues)
{
if (primaryKeyValues == null || primaryKeyValues.Count() == 0)

View File

@ -228,6 +228,15 @@ namespace SqlSugar
};
return this;
}
public IInsertable<T> RemoveDataCache(string likeString)
{
this.RemoveCacheFunc = () =>
{
var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService;
CacheSchemeMain.RemoveCache(cacheService, likeString);
};
return this;
}
public MySqlBlueCopy<T> UseMySql()
{
return new MySqlBlueCopy<T>(this.Context, this.SqlBuilder, InsertObjs);

View File

@ -97,6 +97,15 @@ namespace SqlSugar
};
return this;
}
public IUpdateable<T> RemoveDataCache(string likeString)
{
this.RemoveCacheFunc = () =>
{
var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService;
CacheSchemeMain.RemoveCache(cacheService,likeString);
};
return this;
}
public IUpdateable<T> IsEnableUpdateVersionValidation()
{
this.IsVersionValidation = true;

View File

@ -33,5 +33,23 @@ namespace SqlSugar
}
}
}
public static void RemoveCacheByLike(ICacheService cacheService, string likeString)
{
if (cacheService == null)
{
return;
}
var keys = cacheService.GetAllKey<string>();
if (keys.HasValue())
{
foreach (var item in keys)
{
if (item.ToLower().Contains(likeString))
{
cacheService.Remove<string>(item);
}
}
}
}
}
}

View File

@ -32,6 +32,7 @@ namespace SqlSugar
IDeleteable<T> WhereColumns(Expression<Func<T, object>> columns);
IDeleteable<T> EnableDiffLogEvent(object businessData = null);
IDeleteable<T> RemoveDataCache();
IDeleteable<T> RemoveDataCache(string likeString);
KeyValuePair<string, List<SugarParameter>> ToSql();
void AddQueue();
}

View File

@ -87,6 +87,7 @@ namespace SqlSugar
IUpdateable<T> EnableDiffLogEvent(object businessData = null);
IUpdateable<T> ReSetValue(Expression<Func<T, bool>> setValueExpression);
IUpdateable<T> RemoveDataCache();
IUpdateable<T> RemoveDataCache(string likeString);
IUpdateable<T> CallEntityMethod(Expression<Action<T>> method);
KeyValuePair<string,List<SugarParameter>> ToSql();
void AddQueue();

View File

@ -36,6 +36,7 @@ namespace SqlSugar
IInsertable<T> EnableDiffLogEvent(object businessData = null);
IInsertable<T> RemoveDataCache();
IInsertable<T> RemoveDataCache(string likeString);
KeyValuePair<string, List<SugarParameter>> ToSql();
SqlServerBlueCopy UseSqlServer();
MySqlBlueCopy<T> UseMySql();