From 7797d6cb862e6ffbb23aeb1d1800098739e20fe7 Mon Sep 17 00:00:00 2001 From: sunkaixuna <610262374@qq.com> Date: Wed, 5 Jan 2022 21:11:38 +0800 Subject: [PATCH] Add Db.Fastest.RemoveDataCache --- .../FastestProvider/FastestProvider.cs | 6 +++--- .../Abstract/FastestProvider/Private.cs | 19 +++++++++++++++++++ .../Abstract/FastestProvider/Setting.cs | 13 ++++++++++++- Src/Asp.Net/SqlSugar/Interface/IFastest.cs | 2 ++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/Abstract/FastestProvider/FastestProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/FastestProvider/FastestProvider.cs index 5ae276559..6305ea98d 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/FastestProvider/FastestProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/FastestProvider/FastestProvider.cs @@ -191,12 +191,12 @@ namespace SqlSugar { var title = isAdd ? "BulkCopy" : "BulkUpdate"; 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(List datas,bool isAdd) { var title = isAdd ? "BulkCopy" : "BulkUpdate"; diff --git a/Src/Asp.Net/SqlSugar/Abstract/FastestProvider/Private.cs b/Src/Asp.Net/SqlSugar/Abstract/FastestProvider/Private.cs index 13a38e467..e85aa43d3 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/FastestProvider/Private.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/FastestProvider/Private.cs @@ -161,5 +161,24 @@ namespace SqlSugar tempDataTable.TableName = dt.TableName; 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); + } + } + } + } } diff --git a/Src/Asp.Net/SqlSugar/Abstract/FastestProvider/Setting.cs b/Src/Asp.Net/SqlSugar/Abstract/FastestProvider/Setting.cs index aa4da1b10..0ed7e03ac 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/FastestProvider/Setting.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/FastestProvider/Setting.cs @@ -10,7 +10,18 @@ namespace SqlSugar { private string AsName { get; set; } private int Size { get; set; } - + private string CacheKey { get; set; } + private string CacheKeyLike { get; set; } + public IFastest RemoveDataCache() + { + CacheKey = typeof(T).FullName; + return this; + } + public IFastest RemoveDataCache(string cacheKey) + { + CacheKeyLike = this.context.EntityMaintenance.GetTableName(); + return this; + } public IFastest AS(string tableName) { this.AsName = tableName; diff --git a/Src/Asp.Net/SqlSugar/Interface/IFastest.cs b/Src/Asp.Net/SqlSugar/Interface/IFastest.cs index e51ad16b2..4f3cfe8ae 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IFastest.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IFastest.cs @@ -8,6 +8,8 @@ namespace SqlSugar { public interface IFastest where T:class,new() { + IFastest RemoveDataCache(); + IFastest RemoveDataCache(string cacheKey); IFastest AS(string tableName); IFastest PageSize(int Size); int BulkCopy(List datas);