2017-04-03 15:56:17 +08:00
|
|
|
|
using Bootstrap.Security;
|
2018-06-07 00:45:47 +08:00
|
|
|
|
using Longbow.Cache;
|
2016-11-05 12:11:16 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.DataAccess
|
|
|
|
|
{
|
|
|
|
|
internal static class CacheCleanUtility
|
|
|
|
|
{
|
2018-09-09 19:38:27 +08:00
|
|
|
|
private const string RetrieveAllRolesDataKey = "BootstrapAdminRoleMiddleware-RetrieveRoles";
|
2016-11-05 12:11:16 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="roleIds"></param>
|
|
|
|
|
/// <param name="userIds"></param>
|
|
|
|
|
/// <param name="groupIds"></param>
|
|
|
|
|
/// <param name="menuIds"></param>
|
|
|
|
|
/// <param name="dictIds"></param>
|
2018-09-09 19:38:27 +08:00
|
|
|
|
/// <param name="cacheKey"></param>
|
2018-09-13 19:21:35 +08:00
|
|
|
|
internal static void ClearCache(IEnumerable<int> roleIds = null, IEnumerable<int> userIds = null, IEnumerable<int> groupIds = null, IEnumerable<int> menuIds = null, string dictIds = null, string cacheKey = null)
|
2016-11-05 12:11:16 +08:00
|
|
|
|
{
|
|
|
|
|
var cacheKeys = new List<string>();
|
2018-06-09 19:14:36 +08:00
|
|
|
|
var corsKeys = new List<string>();
|
2016-11-05 12:11:16 +08:00
|
|
|
|
if (roleIds != null)
|
|
|
|
|
{
|
2018-09-13 19:21:35 +08:00
|
|
|
|
roleIds.ToList().ForEach(id =>
|
2016-11-05 12:11:16 +08:00
|
|
|
|
{
|
2017-03-30 16:15:45 +08:00
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByRoleIdDataKey, id));
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByRoleIdDataKey, id));
|
2017-04-13 16:49:48 +08:00
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", MenuHelper.RetrieveMenusByRoleIdDataKey, id));
|
2016-11-05 12:11:16 +08:00
|
|
|
|
});
|
2017-03-22 12:51:41 +08:00
|
|
|
|
cacheKeys.Add(RoleHelper.RetrieveRolesDataKey + "*");
|
2017-04-03 15:56:17 +08:00
|
|
|
|
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
2018-06-07 00:45:47 +08:00
|
|
|
|
cacheKeys.Add(RetrieveAllRolesDataKey + "*");
|
2018-06-09 19:14:36 +08:00
|
|
|
|
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
2016-11-05 12:11:16 +08:00
|
|
|
|
}
|
|
|
|
|
if (userIds != null)
|
|
|
|
|
{
|
2018-09-13 19:21:35 +08:00
|
|
|
|
userIds.ToList().ForEach(id =>
|
2016-11-05 12:11:16 +08:00
|
|
|
|
{
|
2017-03-30 16:15:45 +08:00
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByUserIdDataKey, id));
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIdDataKey, id));
|
2017-04-03 15:56:17 +08:00
|
|
|
|
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
2018-06-09 19:14:36 +08:00
|
|
|
|
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
2016-11-05 12:11:16 +08:00
|
|
|
|
});
|
2017-03-22 12:51:41 +08:00
|
|
|
|
cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*");
|
2018-09-10 18:35:25 +08:00
|
|
|
|
cacheKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
|
|
|
|
|
corsKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
|
2016-11-05 12:11:16 +08:00
|
|
|
|
}
|
|
|
|
|
if (groupIds != null)
|
|
|
|
|
{
|
2018-09-13 19:21:35 +08:00
|
|
|
|
groupIds.ToList().ForEach(id =>
|
2016-11-05 12:11:16 +08:00
|
|
|
|
{
|
2017-03-30 16:15:45 +08:00
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByGroupIdDataKey, id));
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByGroupIdDataKey, id));
|
2016-11-05 12:11:16 +08:00
|
|
|
|
});
|
2017-03-22 12:51:41 +08:00
|
|
|
|
cacheKeys.Add(GroupHelper.RetrieveGroupsDataKey + "*");
|
2017-04-03 15:56:17 +08:00
|
|
|
|
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
2018-06-09 19:14:36 +08:00
|
|
|
|
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
2018-06-07 00:45:47 +08:00
|
|
|
|
cacheKeys.Add(RetrieveAllRolesDataKey + "*");
|
2016-11-05 12:11:16 +08:00
|
|
|
|
}
|
|
|
|
|
if (menuIds != null)
|
|
|
|
|
{
|
2018-09-13 17:55:24 +08:00
|
|
|
|
menuIds.ToList().ForEach(id =>
|
2016-11-05 12:11:16 +08:00
|
|
|
|
{
|
2017-03-30 16:15:45 +08:00
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByMenuIdDataKey, id));
|
2016-11-05 12:11:16 +08:00
|
|
|
|
});
|
2017-04-13 16:49:48 +08:00
|
|
|
|
cacheKeys.Add(MenuHelper.RetrieveMenusByRoleIdDataKey + "*");
|
2017-04-03 15:56:17 +08:00
|
|
|
|
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
2018-06-09 19:14:36 +08:00
|
|
|
|
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
2016-11-05 12:11:16 +08:00
|
|
|
|
}
|
|
|
|
|
if (dictIds != null)
|
|
|
|
|
{
|
2017-04-03 15:56:17 +08:00
|
|
|
|
cacheKeys.Add(BootstrapDict.RetrieveDictsDataKey + "*");
|
2018-09-09 19:38:27 +08:00
|
|
|
|
cacheKeys.Add(DictHelper.RetrieveCategoryDataKey);
|
2018-06-09 19:14:36 +08:00
|
|
|
|
corsKeys.Add(BootstrapDict.RetrieveDictsDataKey + "*");
|
2016-11-05 12:11:16 +08:00
|
|
|
|
}
|
2018-06-09 19:14:36 +08:00
|
|
|
|
if (cacheKey != null)
|
|
|
|
|
{
|
|
|
|
|
cacheKeys.Add(cacheKey);
|
2018-09-10 18:35:25 +08:00
|
|
|
|
corsKeys.Add(cacheKey);
|
2018-06-09 19:14:36 +08:00
|
|
|
|
}
|
|
|
|
|
CacheManager.Clear(cacheKeys);
|
|
|
|
|
CacheManager.CorsClear(corsKeys);
|
2016-11-05 12:11:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|