2019-01-14 17:31:57 +08:00
|
|
|
|
using Longbow.Cache;
|
2016-10-23 23:35:17 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.DataAccess
|
|
|
|
|
{
|
2019-01-14 17:31:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class CacheCleanUtility
|
2016-10-23 23:35:17 +08:00
|
|
|
|
{
|
2019-01-14 17:31:57 +08:00
|
|
|
|
private const string RetrieveAllRolesDataKey = "BootstrapAdminRoleMiddleware-RetrieveRoles";
|
2016-10-23 23:35:17 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="roleIds"></param>
|
|
|
|
|
/// <param name="userIds"></param>
|
|
|
|
|
/// <param name="groupIds"></param>
|
|
|
|
|
/// <param name="menuIds"></param>
|
2019-02-24 17:27:41 +08:00
|
|
|
|
/// <param name="appIds"></param>
|
2016-10-23 23:35:17 +08:00
|
|
|
|
/// <param name="dictIds"></param>
|
2019-01-14 17:31:57 +08:00
|
|
|
|
/// <param name="cacheKey"></param>
|
2019-02-24 17:27:41 +08:00
|
|
|
|
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)
|
2016-10-23 23:35:17 +08:00
|
|
|
|
{
|
|
|
|
|
var cacheKeys = new List<string>();
|
2018-08-13 14:49:54 +08:00
|
|
|
|
var corsKeys = new List<string>();
|
2016-10-23 23:35:17 +08:00
|
|
|
|
if (roleIds != null)
|
|
|
|
|
{
|
2019-01-14 17:31:57 +08:00
|
|
|
|
roleIds.ToList().ForEach(id =>
|
2016-10-23 23:35:17 +08:00
|
|
|
|
{
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByRoleIdDataKey, id));
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByRoleIdDataKey, id));
|
2018-05-05 14:31:03 +08:00
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", MenuHelper.RetrieveMenusByRoleIdDataKey, id));
|
2016-10-23 23:35:17 +08:00
|
|
|
|
});
|
|
|
|
|
cacheKeys.Add(RoleHelper.RetrieveRolesDataKey + "*");
|
2019-01-14 17:31:57 +08:00
|
|
|
|
cacheKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
2018-08-13 14:49:54 +08:00
|
|
|
|
cacheKeys.Add(RetrieveAllRolesDataKey + "*");
|
2019-01-14 17:31:57 +08:00
|
|
|
|
corsKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
2016-10-23 23:35:17 +08:00
|
|
|
|
}
|
|
|
|
|
if (userIds != null)
|
|
|
|
|
{
|
2019-01-14 17:31:57 +08:00
|
|
|
|
userIds.ToList().ForEach(id =>
|
2016-10-23 23:35:17 +08:00
|
|
|
|
{
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByUserIdDataKey, id));
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIdDataKey, id));
|
2019-01-14 17:31:57 +08:00
|
|
|
|
cacheKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
|
|
|
|
corsKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
2016-10-23 23:35:17 +08:00
|
|
|
|
});
|
|
|
|
|
cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*");
|
2019-01-14 17:31:57 +08:00
|
|
|
|
cacheKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
|
|
|
|
|
corsKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
|
2016-10-23 23:35:17 +08:00
|
|
|
|
}
|
|
|
|
|
if (groupIds != null)
|
|
|
|
|
{
|
2019-01-14 17:31:57 +08:00
|
|
|
|
groupIds.ToList().ForEach(id =>
|
2016-10-23 23:35:17 +08:00
|
|
|
|
{
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByGroupIdDataKey, id));
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByGroupIdDataKey, id));
|
|
|
|
|
});
|
|
|
|
|
cacheKeys.Add(GroupHelper.RetrieveGroupsDataKey + "*");
|
2019-01-14 17:31:57 +08:00
|
|
|
|
cacheKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
|
|
|
|
corsKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
2018-08-13 14:49:54 +08:00
|
|
|
|
cacheKeys.Add(RetrieveAllRolesDataKey + "*");
|
2016-10-23 23:35:17 +08:00
|
|
|
|
}
|
|
|
|
|
if (menuIds != null)
|
|
|
|
|
{
|
2019-01-14 17:31:57 +08:00
|
|
|
|
menuIds.ToList().ForEach(id =>
|
2016-10-23 23:35:17 +08:00
|
|
|
|
{
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByMenuIdDataKey, id));
|
|
|
|
|
});
|
2018-05-05 14:31:03 +08:00
|
|
|
|
cacheKeys.Add(MenuHelper.RetrieveMenusByRoleIdDataKey + "*");
|
2019-01-14 17:31:57 +08:00
|
|
|
|
cacheKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
|
|
|
|
corsKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
2016-10-23 23:35:17 +08:00
|
|
|
|
}
|
2019-02-24 17:27:41 +08:00
|
|
|
|
if (appIds != null)
|
|
|
|
|
{
|
|
|
|
|
appIds.ToList().ForEach(id =>
|
|
|
|
|
{
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", AppHelper.RetrieveAppsByRoleIdDataKey, id));
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-10-23 23:35:17 +08:00
|
|
|
|
if (dictIds != null)
|
|
|
|
|
{
|
2019-01-14 17:31:57 +08:00
|
|
|
|
cacheKeys.Add(DictHelper.RetrieveDictsDataKey + "*");
|
|
|
|
|
cacheKeys.Add(DictHelper.RetrieveCategoryDataKey);
|
|
|
|
|
corsKeys.Add(DictHelper.RetrieveDictsDataKey + "*");
|
2016-10-23 23:35:17 +08:00
|
|
|
|
}
|
2018-08-13 14:49:54 +08:00
|
|
|
|
if (cacheKey != null)
|
|
|
|
|
{
|
|
|
|
|
cacheKeys.Add(cacheKey);
|
2019-01-14 17:31:57 +08:00
|
|
|
|
corsKeys.Add(cacheKey);
|
2018-08-13 14:49:54 +08:00
|
|
|
|
}
|
|
|
|
|
CacheManager.Clear(cacheKeys);
|
|
|
|
|
CacheManager.CorsClear(corsKeys);
|
2016-10-23 23:35:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|