feat(#IYJPV): AppHelper 增加缓存

#Issue

close https://gitee.com/LongbowEnterprise/dashboard/issues?id=IYJPV
This commit is contained in:
Argo Zhang 2019-06-30 23:15:43 +08:00
parent ea2fe0f536
commit 63798634a8
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
4 changed files with 9 additions and 8 deletions

View File

@ -5,7 +5,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.5" /> <PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.6" />
<PackageReference Include="Longbow.Data" Version="2.3.2" /> <PackageReference Include="Longbow.Data" Version="2.3.2" />
<PackageReference Include="Longbow.Logging" Version="2.2.8" /> <PackageReference Include="Longbow.Logging" Version="2.2.8" />
<PackageReference Include="Longbow.Security.Cryptography" Version="1.3.0" /> <PackageReference Include="Longbow.Security.Cryptography" Version="1.3.0" />

View File

@ -74,10 +74,8 @@ namespace Bootstrap.DataAccess
} }
if (appIds != null) if (appIds != null)
{ {
appIds.ToList().ForEach(id => cacheKeys.Add("AppHelper-RetrieveAppsBy*");
{ corsKeys.Add("AppHelper-RetrieveAppsBy*");
cacheKeys.Add(string.Format("{0}-{1}", AppHelper.RetrieveAppsByRoleIdDataKey, id));
});
} }
if (dictIds != null) if (dictIds != null)
{ {

View File

@ -1,4 +1,5 @@
using Longbow.Cache; using Bootstrap.Security.DataAccess;
using Longbow.Cache;
using Longbow.Data; using Longbow.Data;
using System.Collections.Generic; using System.Collections.Generic;
@ -39,6 +40,6 @@ namespace Bootstrap.DataAccess
/// </summary> /// </summary>
/// <param name="userName"></param> /// <param name="userName"></param>
/// <returns></returns> /// <returns></returns>
public static IEnumerable<string> RetrievesByUserName(string userName) => DbContextManager.Create<App>().RetrievesByUserName(userName); public static IEnumerable<string> RetrievesByUserName(string userName) => CacheManager.GetOrAdd($"{DbHelper.RetrieveAppsByUserNameDataKey}-{userName}", key => DbContextManager.Create<App>().RetrievesByUserName(userName), DbHelper.RetrieveAppsByUserNameDataKey);
} }
} }

View File

@ -24,8 +24,10 @@ namespace Bootstrap.DataAccess.SqlServer
UserHelper.SaveByRoleId(roleId, new string[] { userId }); UserHelper.SaveByRoleId(roleId, new string[] { userId });
Assert.NotEmpty(AppHelper.RetrievesByUserName("Admin")); Assert.NotEmpty(AppHelper.RetrievesByUserName("Admin"));
var apps = AppHelper.RetrievesByRoleId(roleId);
roleId = RoleHelper.Retrieves().FirstOrDefault(r => r.RoleName == "Default").Id; roleId = RoleHelper.Retrieves().FirstOrDefault(r => r.RoleName == "Default").Id;
userId = UserHelper.Retrieves().FirstOrDefault(u => u.UserName == "User").Id;
UserHelper.SaveByRoleId(roleId, new string[] { userId });
var apps = AppHelper.RetrievesByRoleId(roleId);
AppHelper.SaveByRoleId(roleId, apps.Select(a => a.Id)); AppHelper.SaveByRoleId(roleId, apps.Select(a => a.Id));
Assert.NotEmpty(AppHelper.RetrievesByUserName("User")); Assert.NotEmpty(AppHelper.RetrievesByUserName("User"));
} }