From 42f1a3899423df26930a1e42fbbce02fb672d857 Mon Sep 17 00:00:00 2001 From: Argo-MacBookPro Date: Sat, 9 Jun 2018 19:14:36 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81=EF=BC=9ACa?= =?UTF-8?q?cheCleanUtility=E9=87=8D=E6=96=B0=E5=88=86=E7=B1=BB=E7=BC=93?= =?UTF-8?q?=E5=AD=98Key=EF=BC=8C=E6=9C=AA=E8=B0=83=E7=94=A8CorsClear?= =?UTF-8?q?=E5=81=9A=E5=87=86=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.DataAccess/CacheCleanUtility.cs | 37 +++++++++-------------- Bootstrap.DataAccess/UserHelper.cs | 4 +-- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/Bootstrap.DataAccess/CacheCleanUtility.cs b/Bootstrap.DataAccess/CacheCleanUtility.cs index 42baa17d..e496d2f4 100644 --- a/Bootstrap.DataAccess/CacheCleanUtility.cs +++ b/Bootstrap.DataAccess/CacheCleanUtility.cs @@ -20,9 +20,10 @@ namespace Bootstrap.DataAccess /// /// /// - internal static void ClearCache(string roleIds = null, string userIds = null, string groupIds = null, string menuIds = null, string dictIds = null, string logIds = null, string notifyIds = null, string exceptionIds = null) + internal static void ClearCache(string roleIds = null, string userIds = null, string groupIds = null, string menuIds = null, string dictIds = null, string logIds = null, string notifyIds = null, string exceptionIds = null, string cacheKey = null) { var cacheKeys = new List(); + var corsKeys = new List(); if (roleIds != null) { roleIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(id => @@ -34,6 +35,7 @@ namespace Bootstrap.DataAccess cacheKeys.Add(RoleHelper.RetrieveRolesDataKey + "*"); cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*"); cacheKeys.Add(RetrieveAllRolesDataKey + "*"); + corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*"); } if (userIds != null) { @@ -42,9 +44,11 @@ namespace Bootstrap.DataAccess cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByUserIdDataKey, id)); cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIdDataKey, id)); cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*"); + corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*"); }); cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*"); cacheKeys.Add(BootstrapUser.RetrieveUsersDataKey + "*"); + corsKeys.Add(BootstrapUser.RetrieveUsersDataKey + "*"); } if (groupIds != null) { @@ -55,6 +59,7 @@ namespace Bootstrap.DataAccess }); cacheKeys.Add(GroupHelper.RetrieveGroupsDataKey + "*"); cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*"); + corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*"); cacheKeys.Add(RetrieveAllRolesDataKey + "*"); } if (menuIds != null) @@ -65,10 +70,12 @@ namespace Bootstrap.DataAccess }); cacheKeys.Add(MenuHelper.RetrieveMenusByRoleIdDataKey + "*"); cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*"); + corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*"); } if (dictIds != null) { cacheKeys.Add(BootstrapDict.RetrieveDictsDataKey + "*"); + corsKeys.Add(BootstrapDict.RetrieveDictsDataKey + "*"); } if (logIds != null) { @@ -78,30 +85,16 @@ namespace Bootstrap.DataAccess { cacheKeys.Add(NotificationHelper.RetrieveNotificationsDataKey + "*"); } - if (exceptionIds != null) + if (exceptionIds != null) { cacheKeys.Add(ExceptionHelper.RetrieveExceptionsDataKey + "*"); } - - ClearCache(cacheKeys); - } - /// - /// - /// - /// - internal static void ClearCache(string key) - { - CacheManager.Clear(key); - CacheManager.CorsClear(new List { key }); - } - /// - /// - /// - /// - internal static void ClearCache(IEnumerable keys) - { - CacheManager.Clear(keys); - CacheManager.CorsClear(keys); + if (cacheKey != null) + { + cacheKeys.Add(cacheKey); + } + CacheManager.Clear(cacheKeys); + CacheManager.CorsClear(corsKeys); } } } diff --git a/Bootstrap.DataAccess/UserHelper.cs b/Bootstrap.DataAccess/UserHelper.cs index 3396b47e..35b5792e 100644 --- a/Bootstrap.DataAccess/UserHelper.cs +++ b/Bootstrap.DataAccess/UserHelper.cs @@ -327,7 +327,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", userName)); DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); string key = string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName); - CacheCleanUtility.ClearCache(key); + CacheCleanUtility.ClearCache(cacheKey: key); ret = true; } } @@ -355,7 +355,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", userName)); DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); string key = string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName); - CacheCleanUtility.ClearCache(key); + CacheCleanUtility.ClearCache(cacheKey: key); ret = true; } }