Browse Source

Merge pull request #2523 from abpframework/maliming/settingCache

Make SettingCacheItem ignore multi-tenancy.
pull/2563/head
Halil İbrahim Kalkan 7 years ago
committed by GitHub
parent
commit
d63b1a44ae
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/SettingCacheItem.cs
  2. 38
      modules/setting-management/test/Volo.Abp.SettingManagement.Tests/Volo/Abp/SettingManagement/SettingCacheItemInvalidator_Tests.cs

2
modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/SettingCacheItem.cs

@ -1,8 +1,10 @@
using System; using System;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.SettingManagement namespace Volo.Abp.SettingManagement
{ {
[Serializable] [Serializable]
[IgnoreMultiTenancy]
public class SettingCacheItem public class SettingCacheItem
{ {
public string Value { get; set; } public string Value { get; set; }

38
modules/setting-management/test/Volo.Abp.SettingManagement.Tests/Volo/Abp/SettingManagement/SettingCacheItemInvalidator_Tests.cs

@ -1,10 +1,8 @@
using System; using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Castle.DynamicProxy.Generators;
using Shouldly; using Shouldly;
using Volo.Abp.Caching; using Volo.Abp.Caching;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Settings; using Volo.Abp.Settings;
using Xunit; using Xunit;
@ -16,6 +14,7 @@ namespace Volo.Abp.SettingManagement
private readonly ISettingManagementStore _settingManagementStore; private readonly ISettingManagementStore _settingManagementStore;
private readonly ISettingRepository _settingRepository; private readonly ISettingRepository _settingRepository;
private readonly SettingTestData _testData; private readonly SettingTestData _testData;
private readonly ICurrentTenant _currentTenant;
public SettingCacheItemInvalidator_Tests() public SettingCacheItemInvalidator_Tests()
{ {
@ -23,6 +22,7 @@ namespace Volo.Abp.SettingManagement
_cache = GetRequiredService<IDistributedCache<SettingCacheItem>>(); _cache = GetRequiredService<IDistributedCache<SettingCacheItem>>();
_settingRepository = GetRequiredService<ISettingRepository>(); _settingRepository = GetRequiredService<ISettingRepository>();
_testData = GetRequiredService<SettingTestData>(); _testData = GetRequiredService<SettingTestData>();
_currentTenant = GetRequiredService<ICurrentTenant>();
} }
[Fact] [Fact]
@ -49,5 +49,35 @@ namespace Volo.Abp.SettingManagement
(await _cache.GetAsync( (await _cache.GetAsync(
SettingCacheItem.CalculateCacheKey("MySetting2", UserSettingValueProvider.ProviderName, _testData.User1Id.ToString())).ConfigureAwait(false)).ShouldBeNull(); SettingCacheItem.CalculateCacheKey("MySetting2", UserSettingValueProvider.ProviderName, _testData.User1Id.ToString())).ConfigureAwait(false)).ShouldBeNull();
} }
[Fact]
public async Task Cache_Should_Invalidator_WhenSettingChanged_Between_Tenant_And_Host()
{
var tenantId = Guid.NewGuid();
using (_currentTenant.Change(tenantId))
{
// GetOrNullAsync will cache language.
await _settingManagementStore
.GetOrNullAsync("MySetting2", GlobalSettingValueProvider.ProviderName, null)
.ConfigureAwait(false);
}
using (_currentTenant.Change(null))
{
// SetAsync will make cache invalid.
await _settingManagementStore
.SetAsync("MySetting2", "MySetting2Value", GlobalSettingValueProvider.ProviderName, null)
.ConfigureAwait(false);
}
using (_currentTenant.Change(tenantId))
{
// Assert
(await _cache.GetAsync(
SettingCacheItem.CalculateCacheKey("MySetting2", GlobalSettingValueProvider.ProviderName, null))
.ConfigureAwait(false)).ShouldBeNull();
}
}
} }
} }

Loading…
Cancel
Save