Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DistributedCacheEntryOptions configurable #20205

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -37,6 +38,11 @@ public override void ConfigureServices(ServiceConfigurationContext context)
options.IsDynamicPermissionStoreEnabled = false;
});
}

Configure<DistributedCacheEntryOptions>(options =>
{
options.SlidingExpiration = TimeSpan.FromDays(30);
});
}

public override void OnApplicationInitialization(ApplicationInitializationContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -32,14 +33,16 @@ public DynamicPermissionDefinitionStore(
IDistributedCache distributedCache,
IOptions<AbpDistributedCacheOptions> cacheOptions,
IOptions<PermissionManagementOptions> permissionManagementOptions,
IAbpDistributedLock distributedLock)
IAbpDistributedLock distributedLock,
IOptions<DistributedCacheEntryOptions> distributedCacheEntryOptions)
{
PermissionGroupRepository = permissionGroupRepository;
PermissionRepository = permissionRepository;
PermissionDefinitionSerializer = permissionDefinitionSerializer;
StoreCache = storeCache;
DistributedCache = distributedCache;
DistributedLock = distributedLock;
DistributedCacheEntryOptions = distributedCacheEntryOptions.Value;
PermissionManagementOptions = permissionManagementOptions.Value;
CacheOptions = cacheOptions.Value;
}
Expand Down Expand Up @@ -149,10 +152,7 @@ protected virtual async Task<string> GetOrSetStampInDistributedCache()
await DistributedCache.SetStringAsync(
cacheKey,
stampInDistributedCache,
new DistributedCacheEntryOptions
{
SlidingExpiration = TimeSpan.FromDays(30) //TODO: Make it configurable?
}
DistributedCacheEntryOptions
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -43,7 +44,8 @@ public StaticPermissionSaver(
IAbpDistributedLock distributedLock,
IOptions<AbpPermissionOptions> permissionOptions,
ICancellationTokenProvider cancellationTokenProvider,
IUnitOfWorkManager unitOfWorkManager)
IUnitOfWorkManager unitOfWorkManager,
IOptions<DistributedCacheEntryOptions> distributedCacheEntryOptions)
{
UnitOfWorkManager = unitOfWorkManager;
StaticStore = staticStore;
Expand All @@ -56,6 +58,7 @@ public StaticPermissionSaver(
CancellationTokenProvider = cancellationTokenProvider;
PermissionOptions = permissionOptions.Value;
CacheOptions = cacheOptions.Value;
DistributedCacheEntryOptions = distributedCacheEntryOptions.Value;
}

public async Task SaveAsync()
Expand Down Expand Up @@ -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
);
}
Expand All @@ -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
);
}
Expand Down