-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18412 from abpframework/Clear-Tenant-Cache
Clear the tenant cache when creating/update/deleting.
- Loading branch information
Showing
11 changed files
with
187 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
.../Volo.Abp.MultiTenancy.Abstractions/Volo/Abp/MultiTenancy/TenantConfigurationCacheItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
|
||
namespace Volo.Abp.MultiTenancy; | ||
|
||
[Serializable] | ||
[IgnoreMultiTenancy] | ||
public class TenantConfigurationCacheItem | ||
{ | ||
private const string CacheKeyFormat = "i:{0},n:{1}"; | ||
|
||
public TenantConfiguration? Value { get; set; } | ||
|
||
public TenantConfigurationCacheItem() | ||
{ | ||
|
||
} | ||
|
||
public TenantConfigurationCacheItem(TenantConfiguration? value) | ||
{ | ||
Value = value; | ||
} | ||
|
||
public static string CalculateCacheKey(Guid? id, string? name) | ||
{ | ||
if (id == null && name.IsNullOrWhiteSpace()) | ||
{ | ||
throw new AbpException("Both id and name can't be invalid."); | ||
} | ||
return string.Format(CacheKeyFormat, | ||
id?.ToString() ?? "null", | ||
(name.IsNullOrWhiteSpace() ? "null" : name)); | ||
} | ||
|
||
public static string CalculateCacheKey(Guid id) | ||
{ | ||
return string.Format(CacheKeyFormat, id.ToString(), "null" ); | ||
} | ||
|
||
public static string CalculateCacheKey(string name) | ||
{ | ||
return string.Format(CacheKeyFormat, "null", name); | ||
} | ||
} |
35 changes: 0 additions & 35 deletions
35
...agement/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/TenantCacheItem.cs
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
.../Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/TenantCacheItemInvalidator.cs
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
...antManagement.Domain/Volo/Abp/TenantManagement/TenantConfigurationCacheItemInvalidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Volo.Abp.Caching; | ||
using Volo.Abp.DependencyInjection; | ||
using Volo.Abp.Domain.Entities.Events; | ||
using Volo.Abp.EventBus; | ||
using Volo.Abp.MultiTenancy; | ||
|
||
namespace Volo.Abp.TenantManagement; | ||
|
||
|
||
public class TenantConfigurationCacheItemInvalidator : | ||
ILocalEventHandler<EntityChangedEventData<Tenant>>, | ||
ILocalEventHandler<EntityDeletedEventData<Tenant>>, ITransientDependency | ||
{ | ||
protected IDistributedCache<TenantConfigurationCacheItem> Cache { get; } | ||
|
||
public TenantConfigurationCacheItemInvalidator(IDistributedCache<TenantConfigurationCacheItem> cache) | ||
{ | ||
Cache = cache; | ||
} | ||
|
||
public virtual async Task HandleEventAsync(EntityChangedEventData<Tenant> eventData) | ||
{ | ||
await ClearCacheAsync(eventData.Entity.Id, eventData.Entity.Name); | ||
} | ||
|
||
public virtual async Task HandleEventAsync(EntityDeletedEventData<Tenant> eventData) | ||
{ | ||
await ClearCacheAsync(eventData.Entity.Id, eventData.Entity.Name); | ||
} | ||
|
||
protected virtual async Task ClearCacheAsync(Guid? id, string name) | ||
{ | ||
await Cache.RemoveManyAsync( | ||
new[] | ||
{ | ||
TenantConfigurationCacheItem.CalculateCacheKey(id, null), | ||
TenantConfigurationCacheItem.CalculateCacheKey(null, name), | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.