2017-04-02 16:32:26 +08:00
|
|
|
|
using Longbow.Caching;
|
|
|
|
|
using Longbow.Caching.Configuration;
|
2017-01-09 17:17:28 +08:00
|
|
|
|
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>
|
2017-03-30 16:15:45 +08:00
|
|
|
|
/// <param name="exceptionIds"></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 =>
|
|
|
|
|
{
|
2017-03-30 16:15:45 +08:00
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByRoleIdDataKey, id));
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByRoleIdDataKey, id));
|
2016-11-05 12:11:16 +08:00
|
|
|
|
});
|
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 =>
|
|
|
|
|
{
|
2017-03-30 16:15:45 +08:00
|
|
|
|
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 + "*");
|
2017-03-27 17:27:29 +08:00
|
|
|
|
cacheKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
|
2016-11-05 12:11:16 +08:00
|
|
|
|
}
|
|
|
|
|
if (groupIds != null)
|
|
|
|
|
{
|
|
|
|
|
groupIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(id =>
|
|
|
|
|
{
|
2017-03-30 16:15:45 +08:00
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByGroupIdDataKey, id));
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByGroupIdDataKey, id));
|
2016-11-05 12:11:16 +08:00
|
|
|
|
});
|
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 =>
|
|
|
|
|
{
|
2017-03-30 16:15:45 +08:00
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByMenuIdDataKey, id));
|
2016-11-05 12:11:16 +08:00
|
|
|
|
});
|
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
|
|
|
|
|
2017-04-02 16:32:26 +08:00
|
|
|
|
cacheKeys.AsParallel().ForAll(key => CacheManager.Clear(k => key.EndsWith("*") ? k.Contains(key.TrimEnd('*')) : k.Equals(key)));
|
|
|
|
|
System.Threading.Tasks.Task.Factory.StartNew(() =>
|
2017-03-22 12:51:41 +08:00
|
|
|
|
{
|
2017-04-02 16:32:26 +08:00
|
|
|
|
var section = CacheListSection.GetSection();
|
|
|
|
|
section.Items.Where(item => item.Enabled).Skip(1).AsParallel().ForAll(ele =>
|
2017-03-22 12:51:41 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var client = new WebClient();
|
2017-03-27 17:27:29 +08:00
|
|
|
|
cacheKeys.ForEach(k => client.OpenRead(new Uri(string.Format(ele.Url, k))));
|
2017-03-22 12:51:41 +08:00
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|