feat: 应用程序服务增加缓存
This commit is contained in:
parent
3f0839b12c
commit
383bec6e20
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue