diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/DynamicWebhookDefinitionStore.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/DynamicWebhookDefinitionStore.cs index 76d05070f..126c720c7 100644 --- a/aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/DynamicWebhookDefinitionStore.cs +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/DynamicWebhookDefinitionStore.cs @@ -22,7 +22,7 @@ public class DynamicWebhookDefinitionStore : IDynamicWebhookDefinitionStore, ITr protected IDynamicWebhookDefinitionStoreCache StoreCache { get; } protected IDistributedCache DistributedCache { get; } protected IAbpDistributedLock DistributedLock { get; } - public WebhookManagementOptions WebhookManagementOptions { get; } + protected WebhookManagementOptions WebhookManagementOptions { get; } protected AbpDistributedCacheOptions CacheOptions { get; } public DynamicWebhookDefinitionStore( @@ -90,7 +90,7 @@ public class DynamicWebhookDefinitionStore : IDynamicWebhookDefinitionStore, ITr protected virtual async Task EnsureCacheIsUptoDateAsync() { if (StoreCache.LastCheckTime.HasValue && - DateTime.Now.Subtract(StoreCache.LastCheckTime.Value).TotalSeconds < 30) + DateTime.Now.Subtract(StoreCache.LastCheckTime.Value) < WebhookManagementOptions.WebhooksCacheRefreshInterval) { /* We get the latest webhook with a small delay for optimization */ return; @@ -129,7 +129,7 @@ public class DynamicWebhookDefinitionStore : IDynamicWebhookDefinitionStore, ITr } await using (var commonLockHandle = await DistributedLock - .TryAcquireAsync(GetCommonDistributedLockKey(), TimeSpan.FromMinutes(2))) + .TryAcquireAsync(GetCommonDistributedLockKey(), WebhookManagementOptions.WebhooksCacheStampTimeOut)) { if (commonLockHandle == null) { @@ -152,7 +152,7 @@ public class DynamicWebhookDefinitionStore : IDynamicWebhookDefinitionStore, ITr stampInDistributedCache, new DistributedCacheEntryOptions { - SlidingExpiration = TimeSpan.FromDays(30) //TODO: Make it configurable? + SlidingExpiration = WebhookManagementOptions.WebhooksCacheStampExpiration } ); } diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/WebhookManagementOptions.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/WebhookManagementOptions.cs index f9c4069d6..1cdac2185 100644 --- a/aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/WebhookManagementOptions.cs +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/WebhookManagementOptions.cs @@ -1,12 +1,39 @@ -namespace LINGYUN.Abp.WebhooksManagement; +using System; + +namespace LINGYUN.Abp.WebhooksManagement; public class WebhookManagementOptions { + /// + /// Default: true. + /// public bool SaveStaticWebhooksToDatabase { get; set; } + /// + /// Default: false. + /// public bool IsDynamicWebhookStoreEnabled { get; set; } - + /// + /// 缓存刷新时间 + /// default: 30 seconds + /// + public TimeSpan WebhooksCacheRefreshInterval { get; set; } + /// + /// 申请时间戳超时时间 + /// default: 2 minutes + /// + public TimeSpan WebhooksCacheStampTimeOut { get; set; } + /// + /// 时间戳过期时间 + /// default: 30 minutes + /// + public TimeSpan WebhooksCacheStampExpiration { get; set; } public WebhookManagementOptions() { IsDynamicWebhookStoreEnabled = true; SaveStaticWebhooksToDatabase = true; + + WebhooksCacheRefreshInterval = TimeSpan.FromSeconds(30); + WebhooksCacheStampTimeOut = TimeSpan.FromMinutes(2); + // 30分钟过期重新刷新缓存 + WebhooksCacheStampExpiration = TimeSpan.FromMinutes(30); } }