diff --git a/Src/Asp.Net/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs index 374d1e918..72bd6c6a0 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs @@ -238,7 +238,15 @@ namespace SqlSugar }; return this; } - + public IDeleteable RemoveDataCache(string likeString) + { + this.RemoveCacheFunc = () => + { + var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService; + CacheSchemeMain.RemoveCache(cacheService, likeString); + }; + return this; + } public IDeleteable In(List primaryKeyValues) { if (primaryKeyValues == null || primaryKeyValues.Count() == 0) diff --git a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs index 1efa61dee..deff69469 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs @@ -228,6 +228,15 @@ namespace SqlSugar }; return this; } + public IInsertable RemoveDataCache(string likeString) + { + this.RemoveCacheFunc = () => + { + var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService; + CacheSchemeMain.RemoveCache(cacheService, likeString); + }; + return this; + } public MySqlBlueCopy UseMySql() { return new MySqlBlueCopy(this.Context, this.SqlBuilder, InsertObjs); diff --git a/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs index f9d192c18..baa18c6fb 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs @@ -97,6 +97,15 @@ namespace SqlSugar }; return this; } + public IUpdateable RemoveDataCache(string likeString) + { + this.RemoveCacheFunc = () => + { + var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService; + CacheSchemeMain.RemoveCache(cacheService,likeString); + }; + return this; + } public IUpdateable IsEnableUpdateVersionValidation() { this.IsVersionValidation = true; diff --git a/Src/Asp.Net/SqlSugar/CacheScheme/CacheSchemeMain.cs b/Src/Asp.Net/SqlSugar/CacheScheme/CacheSchemeMain.cs index d9bbd4440..1f8b0b23c 100644 --- a/Src/Asp.Net/SqlSugar/CacheScheme/CacheSchemeMain.cs +++ b/Src/Asp.Net/SqlSugar/CacheScheme/CacheSchemeMain.cs @@ -33,5 +33,23 @@ namespace SqlSugar } } } + public static void RemoveCacheByLike(ICacheService cacheService, string likeString) + { + if (cacheService == null) + { + return; + } + var keys = cacheService.GetAllKey(); + if (keys.HasValue()) + { + foreach (var item in keys) + { + if (item.ToLower().Contains(likeString)) + { + cacheService.Remove(item); + } + } + } + } } } diff --git a/Src/Asp.Net/SqlSugar/Interface/IDeleteable.cs b/Src/Asp.Net/SqlSugar/Interface/IDeleteable.cs index e50a40e44..db3006695 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IDeleteable.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IDeleteable.cs @@ -32,6 +32,7 @@ namespace SqlSugar IDeleteable WhereColumns(Expression> columns); IDeleteable EnableDiffLogEvent(object businessData = null); IDeleteable RemoveDataCache(); + IDeleteable RemoveDataCache(string likeString); KeyValuePair> ToSql(); void AddQueue(); } diff --git a/Src/Asp.Net/SqlSugar/Interface/IUpdateable.cs b/Src/Asp.Net/SqlSugar/Interface/IUpdateable.cs index fa2aa7359..74488fd9e 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IUpdateable.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IUpdateable.cs @@ -87,6 +87,7 @@ namespace SqlSugar IUpdateable EnableDiffLogEvent(object businessData = null); IUpdateable ReSetValue(Expression> setValueExpression); IUpdateable RemoveDataCache(); + IUpdateable RemoveDataCache(string likeString); IUpdateable CallEntityMethod(Expression> method); KeyValuePair> ToSql(); void AddQueue(); diff --git a/Src/Asp.Net/SqlSugar/Interface/Insertable.cs b/Src/Asp.Net/SqlSugar/Interface/Insertable.cs index 431c35071..11402f753 100644 --- a/Src/Asp.Net/SqlSugar/Interface/Insertable.cs +++ b/Src/Asp.Net/SqlSugar/Interface/Insertable.cs @@ -36,6 +36,7 @@ namespace SqlSugar IInsertable EnableDiffLogEvent(object businessData = null); IInsertable RemoveDataCache(); + IInsertable RemoveDataCache(string likeString); KeyValuePair> ToSql(); SqlServerBlueCopy UseSqlServer(); MySqlBlueCopy UseMySql();