重写缓存清理逻辑
This commit is contained in:
parent
041edfaf85
commit
67f38ef924
|
@ -10,7 +10,6 @@ namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
internal static class CacheCleanUtility
|
internal static class CacheCleanUtility
|
||||||
{
|
{
|
||||||
private const string CacheListKey = "bd";
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -31,10 +30,8 @@ namespace Bootstrap.DataAccess
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByRoleIDDataKey, 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}", GroupHelper.RetrieveGroupsByRoleIDDataKey, id));
|
||||||
});
|
});
|
||||||
|
cacheKeys.Add(RoleHelper.RetrieveRolesDataKey + "*");
|
||||||
// final cleanup
|
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
|
||||||
CacheManager.Clear(key => cacheKeys.Any(k => k == key) || key.Contains(RoleHelper.RetrieveRolesDataKey) || key.Contains(MenuHelper.RetrieveMenusDataKey));
|
|
||||||
cacheKeys.Clear();
|
|
||||||
}
|
}
|
||||||
if (userIds != null)
|
if (userIds != null)
|
||||||
{
|
{
|
||||||
|
@ -44,10 +41,7 @@ namespace Bootstrap.DataAccess
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIDDataKey, id));
|
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIDDataKey, id));
|
||||||
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey);
|
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey);
|
||||||
});
|
});
|
||||||
cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey);
|
cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*");
|
||||||
// final cleanup
|
|
||||||
CacheManager.Clear(key => cacheKeys.Any(k => k == key) || key.Contains(UserHelper.RetrieveUsersDataKey));
|
|
||||||
cacheKeys.Clear();
|
|
||||||
}
|
}
|
||||||
if (groupIds != null)
|
if (groupIds != null)
|
||||||
{
|
{
|
||||||
|
@ -56,9 +50,8 @@ namespace Bootstrap.DataAccess
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByGroupIDDataKey, id));
|
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByGroupIDDataKey, id));
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByGroupIDDataKey, id));
|
cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByGroupIDDataKey, id));
|
||||||
});
|
});
|
||||||
// final cleanup
|
cacheKeys.Add(GroupHelper.RetrieveGroupsDataKey + "*");
|
||||||
CacheManager.Clear(key => cacheKeys.Any(k => k == key) || key.Contains(GroupHelper.RetrieveGroupsDataKey) || key.Contains(MenuHelper.RetrieveMenusDataKey));
|
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
|
||||||
cacheKeys.Clear();
|
|
||||||
}
|
}
|
||||||
if (menuIds != null)
|
if (menuIds != null)
|
||||||
{
|
{
|
||||||
|
@ -66,54 +59,46 @@ namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByMenuIDDataKey, id));
|
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByMenuIDDataKey, id));
|
||||||
});
|
});
|
||||||
// final cleanup
|
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
|
||||||
CacheManager.Clear(key => cacheKeys.Any(k => k == key) || key.Contains(MenuHelper.RetrieveMenusDataKey));
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
cacheKeys.Clear();
|
|
||||||
}
|
}
|
||||||
if (dictIds != null)
|
if (dictIds != null)
|
||||||
{
|
{
|
||||||
// final cleanup
|
cacheKeys.Add(DictHelper.RetrieveDictsDataKey + "*");
|
||||||
CacheManager.Clear(key => key.Contains(DictHelper.RetrieveDictsDataKey));
|
|
||||||
cacheKeys.Clear();
|
|
||||||
}
|
}
|
||||||
if (logIds != null)
|
if (logIds != null)
|
||||||
{
|
{
|
||||||
// final cleanup
|
cacheKeys.Add(LogHelper.RetrieveLogsDataKey + "*");
|
||||||
CacheManager.Clear(key => key.Contains(LogHelper.RetrieveLogsDataKey));
|
|
||||||
cacheKeys.Clear();
|
|
||||||
}
|
}
|
||||||
if (notifyIds != null)
|
if (notifyIds != null)
|
||||||
{
|
{
|
||||||
// final cleanup
|
cacheKeys.Add(NotificationHelper.RetrieveNotificationsDataKey + "*");
|
||||||
CacheManager.Clear(key => key.Contains(NotificationHelper.RetrieveNotificationsDataKey));
|
|
||||||
cacheKeys.Clear();
|
|
||||||
}
|
}
|
||||||
if (exceptionIds != null)
|
if (exceptionIds != null)
|
||||||
{
|
{
|
||||||
// final cleanup
|
cacheKeys.Add(ExceptionHelper.RetrieveExceptionsDataKey + "*");
|
||||||
CacheManager.Clear(key => key.Contains(ExceptionHelper.RetrieveExceptionsDataKey));
|
|
||||||
cacheKeys.Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue