重构代码:CacheCleanUtility重新分类缓存Key,未调用CorsClear做准备

This commit is contained in:
Argo-MacBookPro 2018-06-09 19:14:36 +08:00
parent 8883e48b61
commit 42f1a38994
2 changed files with 17 additions and 24 deletions

View File

@ -20,9 +20,10 @@ namespace Bootstrap.DataAccess
/// <param name="logIds"></param> /// <param name="logIds"></param>
/// <param name="notifyIds"></param> /// <param name="notifyIds"></param>
/// <param name="exceptionIds"></param> /// <param name="exceptionIds"></param>
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) 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, string cacheKey = null)
{ {
var cacheKeys = new List<string>(); var cacheKeys = new List<string>();
var corsKeys = new List<string>();
if (roleIds != null) if (roleIds != null)
{ {
roleIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(id => roleIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(id =>
@ -34,6 +35,7 @@ namespace Bootstrap.DataAccess
cacheKeys.Add(RoleHelper.RetrieveRolesDataKey + "*"); cacheKeys.Add(RoleHelper.RetrieveRolesDataKey + "*");
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*"); cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
cacheKeys.Add(RetrieveAllRolesDataKey + "*"); cacheKeys.Add(RetrieveAllRolesDataKey + "*");
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
} }
if (userIds != null) if (userIds != null)
{ {
@ -42,9 +44,11 @@ namespace Bootstrap.DataAccess
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByUserIdDataKey, id)); cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByUserIdDataKey, id));
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIdDataKey, id)); cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIdDataKey, id));
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*"); cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
}); });
cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*"); cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*");
cacheKeys.Add(BootstrapUser.RetrieveUsersDataKey + "*"); cacheKeys.Add(BootstrapUser.RetrieveUsersDataKey + "*");
corsKeys.Add(BootstrapUser.RetrieveUsersDataKey + "*");
} }
if (groupIds != null) if (groupIds != null)
{ {
@ -55,6 +59,7 @@ namespace Bootstrap.DataAccess
}); });
cacheKeys.Add(GroupHelper.RetrieveGroupsDataKey + "*"); cacheKeys.Add(GroupHelper.RetrieveGroupsDataKey + "*");
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*"); cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
cacheKeys.Add(RetrieveAllRolesDataKey + "*"); cacheKeys.Add(RetrieveAllRolesDataKey + "*");
} }
if (menuIds != null) if (menuIds != null)
@ -65,10 +70,12 @@ namespace Bootstrap.DataAccess
}); });
cacheKeys.Add(MenuHelper.RetrieveMenusByRoleIdDataKey + "*"); cacheKeys.Add(MenuHelper.RetrieveMenusByRoleIdDataKey + "*");
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*"); cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
} }
if (dictIds != null) if (dictIds != null)
{ {
cacheKeys.Add(BootstrapDict.RetrieveDictsDataKey + "*"); cacheKeys.Add(BootstrapDict.RetrieveDictsDataKey + "*");
corsKeys.Add(BootstrapDict.RetrieveDictsDataKey + "*");
} }
if (logIds != null) if (logIds != null)
{ {
@ -82,26 +89,12 @@ namespace Bootstrap.DataAccess
{ {
cacheKeys.Add(ExceptionHelper.RetrieveExceptionsDataKey + "*"); cacheKeys.Add(ExceptionHelper.RetrieveExceptionsDataKey + "*");
} }
if (cacheKey != null)
ClearCache(cacheKeys); {
} cacheKeys.Add(cacheKey);
/// <summary> }
/// CacheManager.Clear(cacheKeys);
/// </summary> CacheManager.CorsClear(corsKeys);
/// <param name="key"></param>
internal static void ClearCache(string key)
{
CacheManager.Clear(key);
CacheManager.CorsClear(new List<string> { key });
}
/// <summary>
///
/// </summary>
/// <param name="keys"></param>
internal static void ClearCache(IEnumerable<string> keys)
{
CacheManager.Clear(keys);
CacheManager.CorsClear(keys);
} }
} }
} }

View File

@ -327,7 +327,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", userName)); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", userName));
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
string key = string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName); string key = string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName);
CacheCleanUtility.ClearCache(key); CacheCleanUtility.ClearCache(cacheKey: key);
ret = true; ret = true;
} }
} }
@ -355,7 +355,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", userName)); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", userName));
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
string key = string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName); string key = string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName);
CacheCleanUtility.ClearCache(key); CacheCleanUtility.ClearCache(cacheKey: key);
ret = true; ret = true;
} }
} }