Browse Source

Merge pull request #24495 from abpframework/MvcCachedApplicationConfigurationClient

Optimize cache key retrieval in configuration client
pull/24501/head
Engincan VESKE 1 month ago
committed by GitHub
parent
commit
5d177d2da6
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 32
      framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClient.cs

32
framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClient.cs

@ -14,6 +14,8 @@ namespace Volo.Abp.AspNetCore.Mvc.Client;
public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigurationClient, ITransientDependency public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigurationClient, ITransientDependency
{ {
private const string ApplicationConfigurationDtoCacheKey = "ApplicationConfigurationDto_CacheKey";
protected IHttpContextAccessor HttpContextAccessor { get; } protected IHttpContextAccessor HttpContextAccessor { get; }
protected AbpApplicationConfigurationClientProxy ApplicationConfigurationAppService { get; } protected AbpApplicationConfigurationClientProxy ApplicationConfigurationAppService { get; }
protected AbpApplicationLocalizationClientProxy ApplicationLocalizationClientProxy { get; } protected AbpApplicationLocalizationClientProxy ApplicationLocalizationClientProxy { get; }
@ -42,8 +44,21 @@ public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigu
public virtual async Task<ApplicationConfigurationDto> GetAsync() public virtual async Task<ApplicationConfigurationDto> GetAsync()
{ {
var cacheKey = await CreateCacheKeyAsync(); string? cacheKey = null;
var httpContext = HttpContextAccessor?.HttpContext; var httpContext = HttpContextAccessor?.HttpContext;
if (httpContext != null && httpContext.Items[ApplicationConfigurationDtoCacheKey] is string key)
{
cacheKey = key;
}
if (cacheKey.IsNullOrWhiteSpace())
{
cacheKey = await CreateCacheKeyAsync();
if (httpContext != null)
{
httpContext.Items[ApplicationConfigurationDtoCacheKey] = cacheKey;
}
}
if (httpContext != null && httpContext.Items[cacheKey] is ApplicationConfigurationDto configuration) if (httpContext != null && httpContext.Items[cacheKey] is ApplicationConfigurationDto configuration)
{ {
@ -90,8 +105,21 @@ public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigu
public ApplicationConfigurationDto Get() public ApplicationConfigurationDto Get()
{ {
var cacheKey = AsyncHelper.RunSync(CreateCacheKeyAsync); string? cacheKey = null;
var httpContext = HttpContextAccessor?.HttpContext; var httpContext = HttpContextAccessor?.HttpContext;
if (httpContext != null && httpContext.Items[ApplicationConfigurationDtoCacheKey] is string key)
{
cacheKey = key;
}
if (cacheKey.IsNullOrWhiteSpace())
{
cacheKey = AsyncHelper.RunSync(CreateCacheKeyAsync);
if (httpContext != null)
{
httpContext.Items[ApplicationConfigurationDtoCacheKey] = cacheKey;
}
}
if (httpContext != null && httpContext.Items[cacheKey] is ApplicationConfigurationDto configuration) if (httpContext != null && httpContext.Items[cacheKey] is ApplicationConfigurationDto configuration)
{ {

Loading…
Cancel
Save