From 67f38ef924e7e577e2494b161ee3f0f715dd39a6 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Wed, 22 Mar 2017 12:51:41 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99=E7=BC=93=E5=AD=98=E6=B8=85?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.DataAccess/CacheCleanUtility.cs | 79 +++++++++-------------- 1 file changed, 32 insertions(+), 47 deletions(-) diff --git a/Bootstrap.DataAccess/CacheCleanUtility.cs b/Bootstrap.DataAccess/CacheCleanUtility.cs index 8fead40d..9a5c61c3 100644 --- a/Bootstrap.DataAccess/CacheCleanUtility.cs +++ b/Bootstrap.DataAccess/CacheCleanUtility.cs @@ -10,7 +10,6 @@ namespace Bootstrap.DataAccess { internal static class CacheCleanUtility { - private const string CacheListKey = "bd"; /// /// /// @@ -31,10 +30,8 @@ namespace Bootstrap.DataAccess cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByRoleIDDataKey, id)); cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByRoleIDDataKey, id)); }); - - // final cleanup - CacheManager.Clear(key => cacheKeys.Any(k => k == key) || key.Contains(RoleHelper.RetrieveRolesDataKey) || key.Contains(MenuHelper.RetrieveMenusDataKey)); - cacheKeys.Clear(); + cacheKeys.Add(RoleHelper.RetrieveRolesDataKey + "*"); + cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*"); } if (userIds != null) { @@ -44,10 +41,7 @@ namespace Bootstrap.DataAccess cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIDDataKey, id)); cacheKeys.Add(MenuHelper.RetrieveMenusDataKey); }); - cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey); - // final cleanup - CacheManager.Clear(key => cacheKeys.Any(k => k == key) || key.Contains(UserHelper.RetrieveUsersDataKey)); - cacheKeys.Clear(); + cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*"); } if (groupIds != null) { @@ -56,9 +50,8 @@ namespace Bootstrap.DataAccess cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByGroupIDDataKey, id)); cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByGroupIDDataKey, id)); }); - // final cleanup - CacheManager.Clear(key => cacheKeys.Any(k => k == key) || key.Contains(GroupHelper.RetrieveGroupsDataKey) || key.Contains(MenuHelper.RetrieveMenusDataKey)); - cacheKeys.Clear(); + cacheKeys.Add(GroupHelper.RetrieveGroupsDataKey + "*"); + cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*"); } if (menuIds != null) { @@ -66,54 +59,46 @@ namespace Bootstrap.DataAccess { cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByMenuIDDataKey, id)); }); - // final cleanup - CacheManager.Clear(key => cacheKeys.Any(k => k == key) || key.Contains(MenuHelper.RetrieveMenusDataKey)); - var section = CacheListSection.GetSection(); - section.Items.Where(item => item.Enabled && item.Key != CacheListKey).AsParallel().ForAll(ele => - { - System.Threading.Tasks.Task.Factory.StartNew(() => - { - try - { - var client = new WebClient(); - client.OpenRead(new Uri(string.Format(ele.Url, MenuHelper.RetrieveMenusDataKey + "*"))); - } - catch (Exception ex) - { - System.Collections.Specialized.NameValueCollection nv = new System.Collections.Specialized.NameValueCollection(); - nv["ErrorPage"] = ele.Url; - nv["UserId"] = "system"; - nv["UserIp"] = "::1"; - ExceptionManager.Publish(ex, nv); - } - }); - }); - cacheKeys.Clear(); + cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*"); } if (dictIds != null) { - // final cleanup - CacheManager.Clear(key => key.Contains(DictHelper.RetrieveDictsDataKey)); - cacheKeys.Clear(); + cacheKeys.Add(DictHelper.RetrieveDictsDataKey + "*"); } if (logIds != null) { - // final cleanup - CacheManager.Clear(key => key.Contains(LogHelper.RetrieveLogsDataKey)); - cacheKeys.Clear(); + cacheKeys.Add(LogHelper.RetrieveLogsDataKey + "*"); } if (notifyIds != null) { - // final cleanup - CacheManager.Clear(key => key.Contains(NotificationHelper.RetrieveNotificationsDataKey)); - cacheKeys.Clear(); + cacheKeys.Add(NotificationHelper.RetrieveNotificationsDataKey + "*"); } if (exceptionIds != null) { - // final cleanup - CacheManager.Clear(key => key.Contains(ExceptionHelper.RetrieveExceptionsDataKey)); - cacheKeys.Clear(); + cacheKeys.Add(ExceptionHelper.RetrieveExceptionsDataKey + "*"); } + + var section = CacheListSection.GetSection(); + section.Items.Where(item => item.Enabled).AsParallel().ForAll(ele => + { + System.Threading.Tasks.Task.Factory.StartNew(() => + { + try + { + var client = new WebClient(); + cacheKeys.ForEach(k => client.OpenReadAsync(new Uri(string.Format(ele.Url, k)))); + + } + catch (Exception ex) + { + System.Collections.Specialized.NameValueCollection nv = new System.Collections.Specialized.NameValueCollection(); + nv["ErrorPage"] = ele.Url; + nv["UserId"] = "system"; + nv["UserIp"] = "::1"; + ExceptionManager.Publish(ex, nv); + } + }); + }); } } }