From 51f30f873a0d7da6b5544eb8ec462f7e73789339 Mon Sep 17 00:00:00 2001 From: NoahLan <6995syu@163.com> Date: Tue, 26 Mar 2024 10:51:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A1=A5=E5=85=85=E5=88=86=E5=B8=83?= =?UTF-8?q?=E5=BC=8F=E7=BC=93=E5=AD=98=E7=9A=84Key=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NPinDistributedCacheKeyNormalizer.cs | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) 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