2019-05-01 16:46:24 +08:00
|
|
|
|
using Longbow.Cache;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.DataAccess
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2019-08-10 17:12:45 +08:00
|
|
|
|
/// 缓存清理操作类
|
2019-05-01 16:46:24 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public static class CacheCleanUtility
|
|
|
|
|
{
|
|
|
|
|
private const string RetrieveAllRolesDataKey = "BootstrapAdminRoleMiddleware-RetrieveRoles";
|
|
|
|
|
/// <summary>
|
2019-08-10 17:12:45 +08:00
|
|
|
|
/// 清理缓存
|
2019-05-01 16:46:24 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="roleIds"></param>
|
|
|
|
|
/// <param name="userIds"></param>
|
|
|
|
|
/// <param name="groupIds"></param>
|
|
|
|
|
/// <param name="menuIds"></param>
|
|
|
|
|
/// <param name="appIds"></param>
|
|
|
|
|
/// <param name="dictIds"></param>
|
|
|
|
|
/// <param name="cacheKey"></param>
|
|
|
|
|
public static void ClearCache(IEnumerable<string> roleIds = null, IEnumerable<string> userIds = null, IEnumerable<string> groupIds = null, IEnumerable<string> menuIds = null, IEnumerable<string> appIds = null, IEnumerable<string> dictIds = null, string cacheKey = null)
|
|
|
|
|
{
|
|
|
|
|
var cacheKeys = new List<string>();
|
|
|
|
|
var corsKeys = new List<string>();
|
|
|
|
|
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 + "*");
|
|
|
|
|
});
|
|
|
|
|
cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*");
|
|
|
|
|
cacheKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
|
|
|
|
|
corsKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
|
2019-08-10 17:12:45 +08:00
|
|
|
|
corsKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
2019-05-01 16:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
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 (appIds != null)
|
|
|
|
|
{
|
2019-06-30 23:15:43 +08:00
|
|
|
|
cacheKeys.Add("AppHelper-RetrieveAppsBy*");
|
|
|
|
|
corsKeys.Add("AppHelper-RetrieveAppsBy*");
|
2019-05-01 16:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
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);
|
2019-08-10 17:12:45 +08:00
|
|
|
|
CacheManager.CorsClear(corsKeys.Distinct());
|
2019-05-01 16:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|