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

View File

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