重构代码:整理Bootstrap.Security.Client工程缓存配置
This commit is contained in:
parent
53b2a2e666
commit
33e9c09c01
|
@ -12,6 +12,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Bootstrap.Security.SQLServer" Version="1.0.0" />
|
||||
<PackageReference Include="Longbow.Cache" Version="1.0.2" />
|
||||
<PackageReference Include="Longbow.Web" Version="1.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Bootstrap.Security;
|
||||
using Bootstrap.Security.SQLServer;
|
||||
using Longbow.Cache;
|
||||
using Longbow.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -12,6 +13,13 @@ namespace Bootstrap.Client.DataAccess
|
|||
/// </summary>
|
||||
public static class DictHelper
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// 缓存索引,BootstrapAdmin后台清理缓存时使用
|
||||
/// </summary>
|
||||
public const string RetrieveDictsDataKey = "BootstrapDict-RetrieveDicts";
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
@ -48,7 +56,7 @@ namespace Bootstrap.Client.DataAccess
|
|||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static IEnumerable<BootstrapDict> RetrieveDicts() => BASQLHelper.RetrieveDicts();
|
||||
private static IEnumerable<BootstrapDict> RetrieveDicts() => CacheManager.GetOrAdd(RetrieveDictsDataKey, key => BASQLHelper.RetrieveDicts());
|
||||
|
||||
private static string RetrieveAppName(string name, string defaultValue = "未设置")
|
||||
{
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
using Bootstrap.Security;
|
||||
using Bootstrap.Security.SQLServer;
|
||||
using Longbow.Cache;
|
||||
using Longbow.Configuration;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Bootstrap.Client.DataAccess
|
||||
{
|
||||
|
@ -13,9 +15,26 @@ namespace Bootstrap.Client.DataAccess
|
|||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="url"></param>
|
||||
public const string RetrieveMenusAll = "BootstrapMenu-RetrieveMenus";
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="activeUrl"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<BootstrapMenu> RetrieveAppMenus(string userName, string url) => BASQLHelper.RetrieveAppMenus(ConfigurationManager.AppSettings["AppId"], userName, url);
|
||||
public static IEnumerable<BootstrapMenu> RetrieveAppMenus(string userName, string activeUrl)
|
||||
{
|
||||
var menus = RetrieveAllMenus(userName).Where(m => m.Category == "1" && m.IsResource == 0 && m.ApplicationCode == ConfigurationManager.AppSettings["AppId"]);
|
||||
BASQLHelper.ActiveMenu(null, menus, activeUrl);
|
||||
var root = menus.Where(m => m.ParentId == 0).OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order);
|
||||
BASQLHelper.CascadeMenus(menus, root);
|
||||
return root;
|
||||
}
|
||||
/// <summary>
|
||||
/// 通过用户获得所有菜单
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
private static IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName) => CacheManager.GetOrAdd($"{RetrieveMenusAll}-{userName}", key => BASQLHelper.RetrieveAllMenus(userName), RetrieveMenusAll);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using Bootstrap.Security;
|
||||
using Bootstrap.Security.SQLServer;
|
||||
using Bootstrap.Security.SQLServer;
|
||||
using Longbow.Cache;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Bootstrap.Client.DataAccess
|
||||
|
@ -9,17 +9,19 @@ namespace Bootstrap.Client.DataAccess
|
|||
/// </summary>
|
||||
public static class RoleHelper
|
||||
{
|
||||
public const string RetrieveRolesByUserNameDataKey = "BootstrapRole-RetrieveRolesByUserName";
|
||||
public const string RetrieveRolesByUrlDataKey = "BootstrapRole-RetrieveRolesByUrl";
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<string> RetrieveRolesByUserName(string userName) => BASQLHelper.RetrieveRolesByUserName(userName);
|
||||
public static IEnumerable<string> RetrieveRolesByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByUserNameDataKey, userName), key => BASQLHelper.RetrieveRolesByUserName(userName), RetrieveRolesByUserNameDataKey);
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<string> RetrieveRolesByUrl(string url) => BASQLHelper.RetrieveRolesByUrl(url);
|
||||
public static IEnumerable<string> RetrieveRolesByUrl(string url) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByUrlDataKey, url), key => BASQLHelper.RetrieveRolesByUrl(url), RetrieveRolesByUrlDataKey);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
using Bootstrap.Security;
|
||||
using Bootstrap.Security.SQLServer;
|
||||
using Longbow.Cache;
|
||||
|
||||
namespace Bootstrap.Client.DataAccess
|
||||
{
|
||||
|
@ -8,11 +9,12 @@ namespace Bootstrap.Client.DataAccess
|
|||
/// </summary>
|
||||
public static class UserHelper
|
||||
{
|
||||
public const string RetrieveUsersByNameDataKey = "BootstrapUser-RetrieveUsersByName";
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public static BootstrapUser RetrieveUserByUserName(string userName) => BASQLHelper.RetrieveUserByUserName(userName);
|
||||
public static BootstrapUser RetrieveUserByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName), k => BASQLHelper.RetrieveUserByUserName(userName), RetrieveUsersByNameDataKey);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,27 +35,6 @@
|
|||
}
|
||||
],
|
||||
"CacheItems": [
|
||||
{
|
||||
"Enabled": true,
|
||||
"Key": "BootstrapAdminAuthorizeFilter-RetrieveRolesByUrl",
|
||||
"Interval": 600,
|
||||
"SlidingExpiration": true,
|
||||
"Desc": "通过菜单获得所有角色数据"
|
||||
},
|
||||
{
|
||||
"Enabled": true,
|
||||
"Key": "BootstrapAdminGroupMiddleware-RetrieveGroupsByUserName",
|
||||
"Interval": 600,
|
||||
"SlidingExpiration": true,
|
||||
"Desc": "指定用户所有组数据缓存"
|
||||
},
|
||||
{
|
||||
"Enabled": true,
|
||||
"Key": "BootstrapAdminRoleMiddleware-RetrieveRolesByUserName",
|
||||
"Interval": 600,
|
||||
"SlidingExpiration": true,
|
||||
"Desc": "指定用户角色数据缓存"
|
||||
},
|
||||
{
|
||||
"Enabled": true,
|
||||
"Key": "BootstrapDict-RetrieveDicts",
|
||||
|
@ -65,11 +44,25 @@
|
|||
},
|
||||
{
|
||||
"Enabled": true,
|
||||
"Key": "BootstrapMenu-RetrieveMenusByUserName",
|
||||
"Key": "BootstrapMenu-RetrieveMenus",
|
||||
"Interval": 600,
|
||||
"SlidingExpiration": true,
|
||||
"Desc": "用户所有菜单数据缓存"
|
||||
},
|
||||
{
|
||||
"Enabled": true,
|
||||
"Key": "BootstrapRole-RetrieveRolesByUserName",
|
||||
"Interval": 600,
|
||||
"SlidingExpiration": true,
|
||||
"Desc": "指定用户角色数据缓存"
|
||||
},
|
||||
{
|
||||
"Enabled": true,
|
||||
"Key": "BootstrapRole-RetrieveRolesByUrl",
|
||||
"Interval": 600,
|
||||
"SlidingExpiration": true,
|
||||
"Desc": "通过菜单获得所有角色数据"
|
||||
},
|
||||
{
|
||||
"Enabled": true,
|
||||
"Key": "BootstrapUser-RetrieveUsersByName",
|
||||
|
|
Loading…
Reference in New Issue