feat: 补充分布式缓存的Key序列化

main
NoahLan 7 months ago
parent aa4d042b78
commit 51f30f873a

@ -1,6 +1,37 @@
namespace NPin.Framework.Caching.FreeRedis;
public class NPinDistributedCacheKeyNormalizer
{
using Microsoft.Extensions.Options;
using Volo.Abp.Caching;
using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy;
namespace NPin.Framework.Caching.FreeRedis;
/// <summary>
/// 分布式缓存的Key序列化
/// 添加多租户支持
/// </summary>
[Dependency(ReplaceServices = true)]
public class NPinDistributedCacheKeyNormalizer : IDistributedCacheKeyNormalizer, ITransientDependency
{
protected ICurrentTenant CurrentTenant { get; }
protected AbpDistributedCacheOptions DistributedCacheOptions { get; }
public NPinDistributedCacheKeyNormalizer(ICurrentTenant currentTenant,
IOptions<AbpDistributedCacheOptions> distributedCacheOptions)
{
CurrentTenant = currentTenant;
DistributedCacheOptions = distributedCacheOptions.Value;
}
public string NormalizeKey(DistributedCacheKeyNormalizeArgs args)
{
var ret = $"{DistributedCacheOptions.KeyPrefix}{args.Key}";
// if (!args.IgnoreMultiTenancy && CurrentTenant.Id.HasValue)
// {
// ret = $"t:{CurrentTenant.Id.Value},{ret}";
// }
return ret;
}
}
Loading…
Cancel
Save