Browse Source

Merge pull request #24995 from abpframework/auto-merge/rel-10-1/4394

Merge branch rel-10.2 with rel-10.1
pull/24996/head
Volosoft Agent 7 months ago
committed by GitHub
parent
commit
4c3c365062
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 17
      framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClient.cs

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

@ -16,7 +16,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Client;
public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigurationClient, ITransientDependency public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigurationClient, ITransientDependency
{ {
private const string ApplicationConfigurationDtoCacheKey = "ApplicationConfigurationDto_CacheKey"; private const string HttpContextItemsCacheKeyFormat = "ApplicationConfigurationDto_{0}_{1}_CacheKey";
protected IHttpContextAccessor HttpContextAccessor { get; } protected IHttpContextAccessor HttpContextAccessor { get; }
protected AbpApplicationConfigurationClientProxy ApplicationConfigurationAppService { get; } protected AbpApplicationConfigurationClientProxy ApplicationConfigurationAppService { get; }
@ -48,7 +48,8 @@ public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigu
{ {
string? cacheKey = null; string? cacheKey = null;
var httpContext = HttpContextAccessor?.HttpContext; var httpContext = HttpContextAccessor?.HttpContext;
if (httpContext != null && httpContext.Items[ApplicationConfigurationDtoCacheKey] is string key) var itemsKey = GetHttpContextItemsCacheKey();
if (httpContext != null && httpContext.Items[itemsKey] is string key)
{ {
cacheKey = key; cacheKey = key;
} }
@ -58,7 +59,7 @@ public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigu
cacheKey = await CreateCacheKeyAsync(); cacheKey = await CreateCacheKeyAsync();
if (httpContext != null) if (httpContext != null)
{ {
httpContext.Items[ApplicationConfigurationDtoCacheKey] = cacheKey; httpContext.Items[itemsKey] = cacheKey;
} }
} }
@ -128,7 +129,8 @@ public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigu
{ {
string? cacheKey = null; string? cacheKey = null;
var httpContext = HttpContextAccessor?.HttpContext; var httpContext = HttpContextAccessor?.HttpContext;
if (httpContext != null && httpContext.Items[ApplicationConfigurationDtoCacheKey] is string key) var itemsKey = GetHttpContextItemsCacheKey();
if (httpContext != null && httpContext.Items[itemsKey] is string key)
{ {
cacheKey = key; cacheKey = key;
} }
@ -138,7 +140,7 @@ public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigu
cacheKey = AsyncHelper.RunSync(CreateCacheKeyAsync); cacheKey = AsyncHelper.RunSync(CreateCacheKeyAsync);
if (httpContext != null) if (httpContext != null)
{ {
httpContext.Items[ApplicationConfigurationDtoCacheKey] = cacheKey; httpContext.Items[itemsKey] = cacheKey;
} }
} }
@ -154,4 +156,9 @@ public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigu
{ {
return await CacheHelper.CreateCacheKeyAsync(CurrentUser.Id); return await CacheHelper.CreateCacheKeyAsync(CurrentUser.Id);
} }
protected virtual string GetHttpContextItemsCacheKey()
{
return string.Format(CultureInfo.InvariantCulture, HttpContextItemsCacheKeyFormat, CurrentUser.Id?.ToString("N") ?? "Anonymous", CultureInfo.CurrentUICulture.Name);
}
} }

Loading…
Cancel
Save