41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using Microsoft.Extensions.Options;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp.Caching;
|
|
using Volo.Abp.DependencyInjection;
|
|
using Volo.Abp.MultiTenancy;
|
|
|
|
namespace Syc.Abp.Caching.Redis
|
|
{
|
|
[Dependency(Microsoft.Extensions.DependencyInjection.ServiceLifetime.Transient,ReplaceServices = true)]
|
|
public class DefaultDistributedCacheKeyNormalizer : IDistributedCacheKeyNormalizer
|
|
{
|
|
protected ICurrentTenant CurrentTenant { get; }
|
|
|
|
protected AbpDistributedCacheOptions DistributedCacheOptions { get; }
|
|
|
|
public DefaultDistributedCacheKeyNormalizer(
|
|
ICurrentTenant currentTenant,
|
|
IOptions<AbpDistributedCacheOptions> distributedCacheOptions)
|
|
{
|
|
CurrentTenant = currentTenant;
|
|
DistributedCacheOptions = distributedCacheOptions.Value;
|
|
}
|
|
|
|
public virtual string NormalizeKey(DistributedCacheKeyNormalizeArgs args)
|
|
{
|
|
var normalizedKey = $"{DistributedCacheOptions.KeyPrefix}{args.Key}";
|
|
|
|
if (!args.IgnoreMultiTenancy && CurrentTenant.Id.HasValue)
|
|
{
|
|
normalizedKey = $"t:{CurrentTenant.Id.Value},{normalizedKey}";
|
|
}
|
|
|
|
return normalizedKey;
|
|
}
|
|
}
|
|
}
|