mirror of https://github.com/abpframework/abp.git
4 changed files with 83 additions and 15 deletions
@ -0,0 +1,21 @@ |
|||
namespace Volo.Abp.Caching |
|||
{ |
|||
public class DistributedCacheKeyNormalizeArgs |
|||
{ |
|||
public string Key { get; } |
|||
|
|||
public string CacheName { get; } |
|||
|
|||
public bool IgnoreMultiTenancy { get; } |
|||
|
|||
public DistributedCacheKeyNormalizeArgs( |
|||
string key, |
|||
string cacheName, |
|||
bool ignoreMultiTenancy) |
|||
{ |
|||
Key = key; |
|||
CacheName = cacheName; |
|||
IgnoreMultiTenancy = ignoreMultiTenancy; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace Volo.Abp.Caching |
|||
{ |
|||
public class DistributedCacheKeyNormalizer : IDistributedCacheKeyNormalizer, ITransientDependency |
|||
{ |
|||
protected ICurrentTenant CurrentTenant { get; } |
|||
|
|||
protected AbpDistributedCacheOptions DistributedCacheOptions { get; } |
|||
|
|||
public DistributedCacheKeyNormalizer( |
|||
ICurrentTenant currentTenant, |
|||
IOptions<AbpDistributedCacheOptions> distributedCacheOptions) |
|||
{ |
|||
CurrentTenant = currentTenant; |
|||
DistributedCacheOptions = distributedCacheOptions.Value; |
|||
} |
|||
|
|||
public virtual string NormalizeKey(DistributedCacheKeyNormalizeArgs args) |
|||
{ |
|||
var normalizedKey = $"c:{args.CacheName},k:{DistributedCacheOptions.KeyPrefix}{args.Key}"; |
|||
|
|||
if (!args.IgnoreMultiTenancy && CurrentTenant.Id.HasValue) |
|||
{ |
|||
normalizedKey = $"t:{CurrentTenant.Id.Value},{normalizedKey}"; |
|||
} |
|||
|
|||
return normalizedKey; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.Caching |
|||
{ |
|||
public interface IDistributedCacheKeyNormalizer |
|||
{ |
|||
string NormalizeKey(DistributedCacheKeyNormalizeArgs args); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue