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
|
|
|
|
|
{
|
2017-01-09 17:17:28 +08:00
|
|
|
|
private const string CacheListKey = "bd";
|
2016-11-05 12:11:16 +08:00
|
|
|
|
/// <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));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// final cleanup
|
|
|
|
|
CacheManager.Clear(key => cacheKeys.Any(k => k == key) || key.Contains(RoleHelper.RetrieveRolesDataKey) || key.Contains(MenuHelper.RetrieveMenusDataKey));
|
|
|
|
|
cacheKeys.Clear();
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
});
|
2016-11-11 21:05:41 +08:00
|
|
|
|
cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey);
|
2016-11-05 12:11:16 +08:00
|
|
|
|
// final cleanup
|
2016-12-31 16:49:25 +08:00
|
|
|
|
CacheManager.Clear(key => cacheKeys.Any(k => k == key) || key.Contains(UserHelper.RetrieveUsersDataKey));
|
2016-11-05 12:11:16 +08:00
|
|
|
|
cacheKeys.Clear();
|
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
|
});
|
|
|
|
|
// final cleanup
|
|
|
|
|
CacheManager.Clear(key => cacheKeys.Any(k => k == key) || key.Contains(GroupHelper.RetrieveGroupsDataKey) || key.Contains(MenuHelper.RetrieveMenusDataKey));
|
|
|
|
|
cacheKeys.Clear();
|
|
|
|
|
}
|
|
|
|
|
if (menuIds != null)
|
|
|
|
|
{
|
|
|
|
|
menuIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(id =>
|
|
|
|
|
{
|
|
|
|
|
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByMenuIDDataKey, id));
|
|
|
|
|
});
|
|
|
|
|
// final cleanup
|
|
|
|
|
CacheManager.Clear(key => cacheKeys.Any(k => k == key) || key.Contains(MenuHelper.RetrieveMenusDataKey));
|
2017-01-09 17:17:28 +08:00
|
|
|
|
var section = CacheListSection.GetSection();
|
|
|
|
|
section.Items.Where(item => item.Enabled && item.Key != CacheListKey).AsParallel().ForAll(ele =>
|
|
|
|
|
{
|
|
|
|
|
System.Threading.Tasks.Task.Factory.StartNew(() =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var client = new WebClient();
|
|
|
|
|
client.OpenRead(new Uri(string.Format(ele.Url, MenuHelper.RetrieveMenusDataKey + "*")));
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
cacheKeys.Clear();
|
|
|
|
|
}
|
|
|
|
|
if (dictIds != null)
|
|
|
|
|
{
|
|
|
|
|
// final cleanup
|
|
|
|
|
CacheManager.Clear(key => key.Contains(DictHelper.RetrieveDictsDataKey));
|
|
|
|
|
cacheKeys.Clear();
|
|
|
|
|
}
|
|
|
|
|
if (logIds != null)
|
|
|
|
|
{
|
|
|
|
|
// final cleanup
|
|
|
|
|
CacheManager.Clear(key => key.Contains(LogHelper.RetrieveLogsDataKey));
|
|
|
|
|
cacheKeys.Clear();
|
|
|
|
|
}
|
2016-11-11 09:46:53 +08:00
|
|
|
|
if (notifyIds != null)
|
|
|
|
|
{
|
|
|
|
|
// final cleanup
|
2016-11-11 21:05:41 +08:00
|
|
|
|
CacheManager.Clear(key => key.Contains(NotificationHelper.RetrieveNotificationsDataKey));
|
2016-11-11 09:46:53 +08:00
|
|
|
|
cacheKeys.Clear();
|
|
|
|
|
}
|
2016-11-11 21:44:41 +08:00
|
|
|
|
if (exceptionIds != null)
|
|
|
|
|
{
|
|
|
|
|
// final cleanup
|
|
|
|
|
CacheManager.Clear(key => key.Contains(ExceptionHelper.RetrieveExceptionsDataKey));
|
|
|
|
|
cacheKeys.Clear();
|
|
|
|
|
}
|
2016-11-05 12:11:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|