diff --git a/framework/NPin.Framework.Caching.FreeRedis/NPinDistributedCacheKeyNormalizer.cs b/framework/NPin.Framework.Caching.FreeRedis/NPinDistributedCacheKeyNormalizer.cs index dece29f..5bad63a 100644 --- a/framework/NPin.Framework.Caching.FreeRedis/NPinDistributedCacheKeyNormalizer.cs +++ b/framework/NPin.Framework.Caching.FreeRedis/NPinDistributedCacheKeyNormalizer.cs @@ -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; + +/// +/// 分布式缓存的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; + } } \ No newline at end of file