Add Db.Fastest.RemoveDataCache

This commit is contained in:
sunkaixuna
2022-01-05 21:11:38 +08:00
parent dbd014a561
commit 7797d6cb86
4 changed files with 36 additions and 4 deletions

View File

@@ -191,12 +191,12 @@ namespace SqlSugar
{ {
var title = isAdd ? "BulkCopy" : "BulkUpdate"; var title = isAdd ? "BulkCopy" : "BulkUpdate";
this.context.Ado.IsEnableLogEvent = isLog; this.context.Ado.IsEnableLogEvent = isLog;
if (this.context.CurrentConnectionConfig?.AopEvents?.OnLogExecuted != null) if (this.context.CurrentConnectionConfig?.AopEvents?.OnLogExecuted != null)
{ {
this.context.CurrentConnectionConfig?.AopEvents?.OnLogExecuted($"End {title} name:{GetTableName()} ,count: {datas.Count},current time: {DateTime.Now}" , new SugarParameter[] { }); this.context.CurrentConnectionConfig?.AopEvents?.OnLogExecuted($"End {title} name:{GetTableName()} ,count: {datas.Count},current time: {DateTime.Now}", new SugarParameter[] { });
} }
RemoveCache();
} }
private void Begin<Type>(List<Type> datas,bool isAdd) private void Begin<Type>(List<Type> datas,bool isAdd)
{ {
var title = isAdd ? "BulkCopy" : "BulkUpdate"; var title = isAdd ? "BulkCopy" : "BulkUpdate";

View File

@@ -161,5 +161,24 @@ namespace SqlSugar
tempDataTable.TableName = dt.TableName; tempDataTable.TableName = dt.TableName;
return tempDataTable; return tempDataTable;
} }
private void RemoveCache()
{
if (!string.IsNullOrEmpty(CacheKey) || !string.IsNullOrEmpty(CacheKeyLike))
{
Check.Exception(this.context.CurrentConnectionConfig.ConfigureExternalServices?.DataInfoCacheService == null, "ConnectionConfig.ConfigureExternalServices.DataInfoCacheService is null");
var service = this.context.CurrentConnectionConfig.ConfigureExternalServices?.DataInfoCacheService;
if (!string.IsNullOrEmpty(CacheKey))
{
CacheSchemeMain.RemoveCache(service, CacheKey);
}
if (!string.IsNullOrEmpty(CacheKeyLike))
{
CacheSchemeMain.RemoveCacheByLike(service, CacheKeyLike);
}
}
}
} }
} }

View File

@@ -10,7 +10,18 @@ namespace SqlSugar
{ {
private string AsName { get; set; } private string AsName { get; set; }
private int Size { get; set; } private int Size { get; set; }
private string CacheKey { get; set; }
private string CacheKeyLike { get; set; }
public IFastest<T> RemoveDataCache()
{
CacheKey = typeof(T).FullName;
return this;
}
public IFastest<T> RemoveDataCache(string cacheKey)
{
CacheKeyLike = this.context.EntityMaintenance.GetTableName<T>();
return this;
}
public IFastest<T> AS(string tableName) public IFastest<T> AS(string tableName)
{ {
this.AsName = tableName; this.AsName = tableName;

View File

@@ -8,6 +8,8 @@ namespace SqlSugar
{ {
public interface IFastest<T> where T:class,new() public interface IFastest<T> where T:class,new()
{ {
IFastest<T> RemoveDataCache();
IFastest<T> RemoveDataCache(string cacheKey);
IFastest<T> AS(string tableName); IFastest<T> AS(string tableName);
IFastest<T> PageSize(int Size); IFastest<T> PageSize(int Size);
int BulkCopy(List<T> datas); int BulkCopy(List<T> datas);