using Longbow.Cache; using System.Collections.Generic; using System.Linq; namespace Bootstrap.DataAccess { /// /// /// public static class CacheCleanUtility { private const string RetrieveAllRolesDataKey = "BootstrapAdminRoleMiddleware-RetrieveRoles"; /// /// /// /// /// /// /// /// /// public static void ClearCache(IEnumerable roleIds = null, IEnumerable userIds = null, IEnumerable groupIds = null, IEnumerable menuIds = null, IEnumerable dictIds = null, string cacheKey = null) { var cacheKeys = new List(); var corsKeys = new List(); if (roleIds != null) { roleIds.ToList().ForEach(id => { cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByRoleIdDataKey, id)); cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByRoleIdDataKey, id)); cacheKeys.Add(string.Format("{0}-{1}", MenuHelper.RetrieveMenusByRoleIdDataKey, id)); }); cacheKeys.Add(RoleHelper.RetrieveRolesDataKey + "*"); cacheKeys.Add(MenuHelper.RetrieveMenusAll + "*"); cacheKeys.Add(RetrieveAllRolesDataKey + "*"); corsKeys.Add(MenuHelper.RetrieveMenusAll + "*"); } if (userIds != null) { userIds.ToList().ForEach(id => { cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByUserIdDataKey, id)); cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIdDataKey, id)); cacheKeys.Add(MenuHelper.RetrieveMenusAll + "*"); corsKeys.Add(MenuHelper.RetrieveMenusAll + "*"); }); cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*"); cacheKeys.Add(UserHelper.RetrieveUsersDataKey + "*"); corsKeys.Add(UserHelper.RetrieveUsersDataKey + "*"); } if (groupIds != null) { groupIds.ToList().ForEach(id => { cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByGroupIdDataKey, id)); cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByGroupIdDataKey, id)); }); cacheKeys.Add(GroupHelper.RetrieveGroupsDataKey + "*"); cacheKeys.Add(MenuHelper.RetrieveMenusAll + "*"); corsKeys.Add(MenuHelper.RetrieveMenusAll + "*"); cacheKeys.Add(RetrieveAllRolesDataKey + "*"); } if (menuIds != null) { menuIds.ToList().ForEach(id => { cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByMenuIdDataKey, id)); }); cacheKeys.Add(MenuHelper.RetrieveMenusByRoleIdDataKey + "*"); cacheKeys.Add(MenuHelper.RetrieveMenusAll + "*"); corsKeys.Add(MenuHelper.RetrieveMenusAll + "*"); } if (dictIds != null) { cacheKeys.Add(DictHelper.RetrieveDictsDataKey + "*"); cacheKeys.Add(DictHelper.RetrieveCategoryDataKey); corsKeys.Add(DictHelper.RetrieveDictsDataKey + "*"); } if (cacheKey != null) { cacheKeys.Add(cacheKey); corsKeys.Add(cacheKey); } CacheManager.Clear(cacheKeys); CacheManager.CorsClear(corsKeys); } } }