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;
|
|
|
|
|
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>
|
|
|
|
|
internal static void ClearCache(string roleIds = null, string userIds = null, string groupIds = null, string 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)
|
|
|
|
|
{
|
|
|
|
|
roleIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(id =>
|
|
|
|
|
{
|
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)
|
|
|
|
|
{
|
|
|
|
|
userIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(id =>
|
|
|
|
|
{
|
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)
|
|
|
|
|
{
|
|
|
|
|
groupIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(id =>
|
|
|
|
|
{
|
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)
|
|
|
|
|
{
|
|
|
|
|
menuIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(id =>
|
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|