feat: 应用程序服务增加缓存

This commit is contained in:
Argo-Tianyi 2022-01-27 10:51:59 +08:00
parent 3f0839b12c
commit 383bec6e20
1 changed files with 8 additions and 1 deletions

View File

@ -2,6 +2,7 @@
// Licensed under the LGPL License, Version 3.0. See License.txt in the project root for license information. // Licensed under the LGPL License, Version 3.0. See License.txt in the project root for license information.
// Website: https://admin.blazor.zone // Website: https://admin.blazor.zone
using BootstrapAdmin.Caching;
using BootstrapAdmin.Web.Core; using BootstrapAdmin.Web.Core;
using PetaPoco; using PetaPoco;
@ -9,6 +10,8 @@ namespace BootstrapAdmin.DataAccess.PetaPoco.Services;
class AppService : IApp class AppService : IApp
{ {
private const string AppServiceGetAppsByRoleIdCacheKey = "AppService-GetAppsByRoleId";
private IDatabase Database { get; } private IDatabase Database { get; }
public AppService(IDatabase db) public AppService(IDatabase db)
@ -16,7 +19,7 @@ class AppService : IApp
Database = db; Database = db;
} }
public List<string> GetAppsByRoleId(string? roleId) => Database.Fetch<string>("select AppID from RoleApp where RoleID = @0", roleId); public List<string> GetAppsByRoleId(string? roleId) => CacheManager.GetOrAdd($"{AppServiceGetAppsByRoleIdCacheKey}-{roleId}", entry => Database.Fetch<string>("select AppID from RoleApp where RoleID = @0", roleId));
public bool SaveAppsByRoleId(string? roleId, IEnumerable<string> appIds) public bool SaveAppsByRoleId(string? roleId, IEnumerable<string> appIds)
{ {
@ -34,6 +37,10 @@ class AppService : IApp
Database.AbortTransaction(); Database.AbortTransaction();
throw; throw;
} }
if (ret)
{
CacheManager.Clear();
}
return ret; return ret;
} }
} }