BootstrapAdmin/Bootstrap.DataAccess/CacheCleanUtility.cs

88 lines
4.0 KiB
C#
Raw Normal View History

using Bootstrap.Security;
2018-06-07 00:45:47 +08:00
using Longbow.Cache;
using System.Collections.Generic;
using System.Linq;
namespace Bootstrap.DataAccess
{
internal 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>
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)
{
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));
});
2017-03-22 12:51:41 +08:00
cacheKeys.Add(RoleHelper.RetrieveRolesDataKey + "*");
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
2018-06-07 00:45:47 +08:00
cacheKeys.Add(RetrieveAllRolesDataKey + "*");
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
}
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(BootstrapMenu.RetrieveMenusDataKey + "*");
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
});
2017-03-22 12:51:41 +08:00
cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*");
cacheKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
corsKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
}
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));
});
2017-03-22 12:51:41 +08:00
cacheKeys.Add(GroupHelper.RetrieveGroupsDataKey + "*");
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
2018-06-07 00:45:47 +08:00
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(BootstrapMenu.RetrieveMenusDataKey + "*");
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
}
if (dictIds != null)
{
cacheKeys.Add(BootstrapDict.RetrieveDictsDataKey + "*");
cacheKeys.Add(DictHelper.RetrieveCategoryDataKey);
corsKeys.Add(BootstrapDict.RetrieveDictsDataKey + "*");
}
if (cacheKey != null)
{
cacheKeys.Add(cacheKey);
corsKeys.Add(cacheKey);
}
CacheManager.Clear(cacheKeys);
CacheManager.CorsClear(corsKeys);
}
}
}