2018-10-19 23:09:52 +08:00
|
|
|
|
using Longbow.Cache;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.DataAccess
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class CacheCleanUtility
|
|
|
|
|
{
|
|
|
|
|
private const string RetrieveAllRolesDataKey = "BootstrapAdminRoleMiddleware-RetrieveRoles";
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="roleIds"></param>
|
|
|
|
|
/// <param name="userIds"></param>
|
|
|
|
|
/// <param name="groupIds"></param>
|
|
|
|
|
/// <param name="menuIds"></param>
|
|
|
|
|
/// <param name="dictIds"></param>
|
|
|
|
|
/// <param name="cacheKey"></param>
|
2018-10-30 23:01:36 +08:00
|
|
|
|
public static void ClearCache(IEnumerable<string> roleIds = null, IEnumerable<string> userIds = null, IEnumerable<string> groupIds = null, IEnumerable<string> menuIds = null, IEnumerable<string> dictIds = null, string cacheKey = null)
|
2018-10-19 23:09:52 +08:00
|
|
|
|
{
|
|
|
|
|
var cacheKeys = new List<string>();
|
|
|
|
|
var corsKeys = new List<string>();
|
|
|
|
|
if (roleIds != null)
|
|
|
|
|
{
|
|
|
|
|
roleIds.ToList().ForEach(id =>
|
|
|
|
|
{
|
2018-10-28 15:03:59 +08:00
|
|
|
|
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));
|
2018-10-19 23:09:52 +08:00
|
|
|
|
});
|
2018-10-28 15:03:59 +08:00
|
|
|
|
cacheKeys.Add(RoleHelper.RetrieveRolesDataKey + "*");
|
2018-10-28 20:50:01 +08:00
|
|
|
|
cacheKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
2018-10-19 23:09:52 +08:00
|
|
|
|
cacheKeys.Add(RetrieveAllRolesDataKey + "*");
|
2018-10-28 20:50:01 +08:00
|
|
|
|
corsKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
2018-10-19 23:09:52 +08:00
|
|
|
|
}
|
|
|
|
|
if (userIds != null)
|
|
|
|
|
{
|
|
|
|
|
userIds.ToList().ForEach(id =>
|
|
|
|
|
{
|
2018-10-28 15:03:59 +08:00
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByUserIdDataKey, id));
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIdDataKey, id));
|
2018-10-28 20:50:01 +08:00
|
|
|
|
cacheKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
|
|
|
|
corsKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
2018-10-19 23:09:52 +08:00
|
|
|
|
});
|
2018-10-28 15:03:59 +08:00
|
|
|
|
cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*");
|
|
|
|
|
cacheKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
|
|
|
|
|
corsKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
|
2018-10-19 23:09:52 +08:00
|
|
|
|
}
|
|
|
|
|
if (groupIds != null)
|
|
|
|
|
{
|
|
|
|
|
groupIds.ToList().ForEach(id =>
|
|
|
|
|
{
|
2018-10-28 15:03:59 +08:00
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByGroupIdDataKey, id));
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByGroupIdDataKey, id));
|
2018-10-19 23:09:52 +08:00
|
|
|
|
});
|
2018-10-28 15:03:59 +08:00
|
|
|
|
cacheKeys.Add(GroupHelper.RetrieveGroupsDataKey + "*");
|
2018-10-28 20:50:01 +08:00
|
|
|
|
cacheKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
|
|
|
|
corsKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
2018-10-19 23:09:52 +08:00
|
|
|
|
cacheKeys.Add(RetrieveAllRolesDataKey + "*");
|
|
|
|
|
}
|
|
|
|
|
if (menuIds != null)
|
|
|
|
|
{
|
|
|
|
|
menuIds.ToList().ForEach(id =>
|
|
|
|
|
{
|
2018-10-28 15:03:59 +08:00
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByMenuIdDataKey, id));
|
2018-10-19 23:09:52 +08:00
|
|
|
|
});
|
2018-10-28 15:03:59 +08:00
|
|
|
|
cacheKeys.Add(MenuHelper.RetrieveMenusByRoleIdDataKey + "*");
|
2018-10-28 20:50:01 +08:00
|
|
|
|
cacheKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
|
|
|
|
corsKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
2018-10-19 23:09:52 +08:00
|
|
|
|
}
|
|
|
|
|
if (dictIds != null)
|
|
|
|
|
{
|
2018-10-28 15:42:06 +08:00
|
|
|
|
cacheKeys.Add(DictHelper.RetrieveDictsDataKey + "*");
|
2018-10-28 15:03:59 +08:00
|
|
|
|
cacheKeys.Add(DictHelper.RetrieveCategoryDataKey);
|
2018-10-28 15:42:06 +08:00
|
|
|
|
corsKeys.Add(DictHelper.RetrieveDictsDataKey + "*");
|
2018-10-19 23:09:52 +08:00
|
|
|
|
}
|
|
|
|
|
if (cacheKey != null)
|
|
|
|
|
{
|
|
|
|
|
cacheKeys.Add(cacheKey);
|
|
|
|
|
corsKeys.Add(cacheKey);
|
|
|
|
|
}
|
|
|
|
|
CacheManager.Clear(cacheKeys);
|
|
|
|
|
CacheManager.CorsClear(corsKeys);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|