From b2f20e50b4bcbacf842f4cb971dee04ea385179f Mon Sep 17 00:00:00 2001 From: liuxiaoji <842549829@qq.com> Date: Thu, 11 Jul 2024 10:24:26 +0800 Subject: [PATCH] improvement(DynamicPermissionDefinitionStore,StaticPermissionSaver,AbpPermissionManagementDomainModule):DistributedCacheEntryOptions configurable Change the DistributedCacheEntryOptions to can configure option Instead of directly instantiated --- .../AbpPermissionManagementDomainModule.cs | 6 ++++++ .../DynamicPermissionDefinitionStore.cs | 12 ++++++------ .../PermissionManagement/StaticPermissionSaver.cs | 15 +++++++-------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/AbpPermissionManagementDomainModule.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/AbpPermissionManagementDomainModule.cs index 0f40e3c0399..be8352280c4 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/AbpPermissionManagementDomainModule.cs +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/AbpPermissionManagementDomainModule.cs @@ -1,6 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; @@ -37,6 +38,11 @@ public override void ConfigureServices(ServiceConfigurationContext context) options.IsDynamicPermissionStoreEnabled = false; }); } + + Configure(options => + { + options.SlidingExpiration = TimeSpan.FromDays(30); + }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/DynamicPermissionDefinitionStore.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/DynamicPermissionDefinitionStore.cs index f2e73cefc04..e896a2467b1 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/DynamicPermissionDefinitionStore.cs +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/DynamicPermissionDefinitionStore.cs @@ -23,7 +23,8 @@ public class DynamicPermissionDefinitionStore : IDynamicPermissionDefinitionStor protected IAbpDistributedLock DistributedLock { get; } public PermissionManagementOptions PermissionManagementOptions { get; } protected AbpDistributedCacheOptions CacheOptions { get; } - + protected DistributedCacheEntryOptions DistributedCacheEntryOptions { get; } + public DynamicPermissionDefinitionStore( IPermissionGroupDefinitionRecordRepository permissionGroupRepository, IPermissionDefinitionRecordRepository permissionRepository, @@ -32,7 +33,8 @@ public DynamicPermissionDefinitionStore( IDistributedCache distributedCache, IOptions cacheOptions, IOptions permissionManagementOptions, - IAbpDistributedLock distributedLock) + IAbpDistributedLock distributedLock, + IOptions distributedCacheEntryOptions) { PermissionGroupRepository = permissionGroupRepository; PermissionRepository = permissionRepository; @@ -40,6 +42,7 @@ public DynamicPermissionDefinitionStore( StoreCache = storeCache; DistributedCache = distributedCache; DistributedLock = distributedLock; + DistributedCacheEntryOptions = distributedCacheEntryOptions.Value; PermissionManagementOptions = permissionManagementOptions.Value; CacheOptions = cacheOptions.Value; } @@ -149,10 +152,7 @@ protected virtual async Task GetOrSetStampInDistributedCache() await DistributedCache.SetStringAsync( cacheKey, stampInDistributedCache, - new DistributedCacheEntryOptions - { - SlidingExpiration = TimeSpan.FromDays(30) //TODO: Make it configurable? - } + DistributedCacheEntryOptions ); } diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/StaticPermissionSaver.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/StaticPermissionSaver.cs index 1ef851dac30..3784b738d16 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/StaticPermissionSaver.cs +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/StaticPermissionSaver.cs @@ -31,6 +31,7 @@ public class StaticPermissionSaver : IStaticPermissionSaver, ITransientDependenc protected AbpDistributedCacheOptions CacheOptions { get; } protected IUnitOfWorkManager UnitOfWorkManager { get; } + protected DistributedCacheEntryOptions DistributedCacheEntryOptions { get; } public StaticPermissionSaver( IStaticPermissionDefinitionStore staticStore, @@ -43,7 +44,8 @@ public StaticPermissionSaver( IAbpDistributedLock distributedLock, IOptions permissionOptions, ICancellationTokenProvider cancellationTokenProvider, - IUnitOfWorkManager unitOfWorkManager) + IUnitOfWorkManager unitOfWorkManager, + IOptions distributedCacheEntryOptions) { UnitOfWorkManager = unitOfWorkManager; StaticStore = staticStore; @@ -56,6 +58,7 @@ public StaticPermissionSaver( CancellationTokenProvider = cancellationTokenProvider; PermissionOptions = permissionOptions.Value; CacheOptions = cacheOptions.Value; + DistributedCacheEntryOptions = distributedCacheEntryOptions.Value; } public async Task SaveAsync() @@ -116,9 +119,7 @@ await StaticStore.GetGroupsAsync() await Cache.SetStringAsync( GetCommonStampCacheKey(), Guid.NewGuid().ToString(), - new DistributedCacheEntryOptions { - SlidingExpiration = TimeSpan.FromDays(30) //TODO: Make it configurable? - }, + DistributedCacheEntryOptions, CancellationTokenProvider.Token ); } @@ -143,10 +144,8 @@ await Cache.SetStringAsync( await Cache.SetStringAsync( cacheKey, - currentHash, - new DistributedCacheEntryOptions { - SlidingExpiration = TimeSpan.FromDays(30) //TODO: Make it configurable? - }, + currentHash, + DistributedCacheEntryOptions, CancellationTokenProvider.Token ); }