using Microsoft.Extensions.Options;
using Volo.Abp.Caching;
using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy;
namespace NPin.Framework.Caching.FreeRedis;
///
/// 分布式缓存的Key序列化
/// 添加多租户支持
///
[Dependency(ReplaceServices = true)]
public class NPinDistributedCacheKeyNormalizer : IDistributedCacheKeyNormalizer, ITransientDependency
{
protected ICurrentTenant CurrentTenant { get; }
protected AbpDistributedCacheOptions DistributedCacheOptions { get; }
public NPinDistributedCacheKeyNormalizer(ICurrentTenant currentTenant,
IOptions 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;
}
}