2016-11-05 12:11:16 +08:00
|
|
|
|
using Longbow.Caching;
|
2017-01-09 17:17:28 +08:00
|
|
|
|
using Longbow.Caching.Configuration;
|
|
|
|
|
using Longbow.ExceptionManagement;
|
2016-11-05 12:11:16 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2017-01-09 17:17:28 +08:00
|
|
|
|
using System.Net;
|
2016-11-05 12:11:16 +08:00
|
|
|
|
|
|
|
|
|
namespace Bootstrap.DataAccess
|
|
|
|
|
{
|
|
|
|
|
internal static class CacheCleanUtility
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="roleIds"></param>
|
|
|
|
|
/// <param name="userIds"></param>
|
|
|
|
|
/// <param name="groupIds"></param>
|
|
|
|
|
/// <param name="menuIds"></param>
|
|
|
|
|
/// <param name="dictIds"></param>
|
|
|
|
|
/// <param name="logIds"></param>
|
2016-11-11 13:11:57 +08:00
|
|
|
|
/// <param name="notifyIds"></param>
|
2016-11-11 21:44:41 +08:00
|
|
|
|
internal static void ClearCache(string roleIds = null, string userIds = null, string groupIds = null, string menuIds = null, string dictIds = null, string logIds = null, string notifyIds = null, string exceptionIds = null)
|
2016-11-05 12:11:16 +08:00
|
|
|
|
{
|
|
|
|
|
var cacheKeys = new List<string>();
|
|
|
|
|
if (roleIds != null)
|
|
|
|
|
{
|
|
|
|
|
roleIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(id =>
|
|
|
|
|
{
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByRoleIDDataKey, id));
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByRoleIDDataKey, id));
|
|
|
|
|
});
|
2017-03-22 12:51:41 +08:00
|
|
|
|
cacheKeys.Add(RoleHelper.RetrieveRolesDataKey + "*");
|
|
|
|
|
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
|
2016-11-05 12:11:16 +08:00
|
|
|
|
}
|
|
|
|
|
if (userIds != null)
|
|
|
|
|
{
|
|
|
|
|
userIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(id =>
|
|
|
|
|
{
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByUserIDDataKey, id));
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIDDataKey, id));
|
2016-11-08 20:37:14 +08:00
|
|
|
|
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey);
|
2016-11-05 12:11:16 +08:00
|
|
|
|
});
|
2017-03-22 12:51:41 +08:00
|
|
|
|
cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*");
|
2016-11-05 12:11:16 +08:00
|
|
|
|
}
|
|
|
|
|
if (groupIds != null)
|
|
|
|
|
{
|
|
|
|
|
groupIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).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(MenuHelper.RetrieveMenusDataKey + "*");
|
2016-11-05 12:11:16 +08:00
|
|
|
|
}
|
|
|
|
|
if (menuIds != null)
|
|
|
|
|
{
|
|
|
|
|
menuIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(id =>
|
|
|
|
|
{
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByMenuIDDataKey, id));
|
|
|
|
|
});
|
2017-03-22 12:51:41 +08:00
|
|
|
|
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
|
2016-11-05 12:11:16 +08:00
|
|
|
|
}
|
|
|
|
|
if (dictIds != null)
|
|
|
|
|
{
|
2017-03-22 12:51:41 +08:00
|
|
|
|
cacheKeys.Add(DictHelper.RetrieveDictsDataKey + "*");
|
2016-11-05 12:11:16 +08:00
|
|
|
|
}
|
|
|
|
|
if (logIds != null)
|
|
|
|
|
{
|
2017-03-22 12:51:41 +08:00
|
|
|
|
cacheKeys.Add(LogHelper.RetrieveLogsDataKey + "*");
|
2016-11-05 12:11:16 +08:00
|
|
|
|
}
|
2016-11-11 09:46:53 +08:00
|
|
|
|
if (notifyIds != null)
|
|
|
|
|
{
|
2017-03-22 12:51:41 +08:00
|
|
|
|
cacheKeys.Add(NotificationHelper.RetrieveNotificationsDataKey + "*");
|
2016-11-11 09:46:53 +08:00
|
|
|
|
}
|
2016-11-11 21:44:41 +08:00
|
|
|
|
if (exceptionIds != null)
|
|
|
|
|
{
|
2017-03-22 12:51:41 +08:00
|
|
|
|
cacheKeys.Add(ExceptionHelper.RetrieveExceptionsDataKey + "*");
|
2016-11-11 21:44:41 +08:00
|
|
|
|
}
|
2017-03-22 12:51:41 +08:00
|
|
|
|
|
|
|
|
|
var section = CacheListSection.GetSection();
|
|
|
|
|
section.Items.Where(item => item.Enabled).AsParallel().ForAll(ele =>
|
|
|
|
|
{
|
|
|
|
|
System.Threading.Tasks.Task.Factory.StartNew(() =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var client = new WebClient();
|
|
|
|
|
cacheKeys.ForEach(k => client.OpenReadAsync(new Uri(string.Format(ele.Url, k))));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
System.Collections.Specialized.NameValueCollection nv = new System.Collections.Specialized.NameValueCollection();
|
|
|
|
|
nv["ErrorPage"] = ele.Url;
|
|
|
|
|
nv["UserId"] = "system";
|
|
|
|
|
nv["UserIp"] = "::1";
|
|
|
|
|
ExceptionManager.Publish(ex, nv);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-11-05 12:11:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|