You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.1 KiB
C#

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;
}
}