Browse Source
Optimize cache key retrieval in configuration client
pull/24495/head
maliming
5 months ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
1 changed files with
28 additions and
2 deletions
-
framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClient.cs
|
|
|
@ -42,8 +42,21 @@ public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigu |
|
|
|
|
|
|
|
public virtual async Task<ApplicationConfigurationDto> GetAsync() |
|
|
|
{ |
|
|
|
var cacheKey = await CreateCacheKeyAsync(); |
|
|
|
string? cacheKey = null; |
|
|
|
var httpContext = HttpContextAccessor?.HttpContext; |
|
|
|
if (httpContext != null && httpContext.Items["ApplicationConfigurationDto_CacheKey"] is string key) |
|
|
|
{ |
|
|
|
cacheKey = key; |
|
|
|
} |
|
|
|
|
|
|
|
if (cacheKey.IsNullOrWhiteSpace()) |
|
|
|
{ |
|
|
|
cacheKey = await CreateCacheKeyAsync(); |
|
|
|
if (httpContext != null) |
|
|
|
{ |
|
|
|
httpContext.Items["ApplicationConfigurationDto_CacheKey"] = cacheKey; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (httpContext != null && httpContext.Items[cacheKey] is ApplicationConfigurationDto configuration) |
|
|
|
{ |
|
|
|
@ -90,8 +103,21 @@ public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigu |
|
|
|
|
|
|
|
public ApplicationConfigurationDto Get() |
|
|
|
{ |
|
|
|
var cacheKey = AsyncHelper.RunSync(CreateCacheKeyAsync); |
|
|
|
string? cacheKey = null; |
|
|
|
var httpContext = HttpContextAccessor?.HttpContext; |
|
|
|
if (httpContext != null && httpContext.Items["ApplicationConfigurationDto_CacheKey"] is string key) |
|
|
|
{ |
|
|
|
cacheKey = key; |
|
|
|
} |
|
|
|
|
|
|
|
if (cacheKey.IsNullOrWhiteSpace()) |
|
|
|
{ |
|
|
|
cacheKey = AsyncHelper.RunSync(CreateCacheKeyAsync); |
|
|
|
if (httpContext != null) |
|
|
|
{ |
|
|
|
httpContext.Items["ApplicationConfigurationDto_CacheKey"] = cacheKey; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (httpContext != null && httpContext.Items[cacheKey] is ApplicationConfigurationDto configuration) |
|
|
|
{ |
|
|
|
|