Browse Source

Include UI culture in the HttpContext.Items cache key

pull/24990/head
maliming 7 months ago
parent
commit
ddf9b04b44
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 7
      framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClient.cs

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

@ -1,4 +1,5 @@
using System; using System;
using System.Globalization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Distributed;
@ -14,7 +15,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Client;
public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigurationClient, ITransientDependency public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigurationClient, ITransientDependency
{ {
private const string ApplicationConfigurationDtoCacheKeyFormat = "ApplicationConfigurationDto_{0}_CacheKey"; private const string ApplicationConfigurationDtoCacheKeyFormat = "ApplicationConfigurationDto_{0}_{1}_CacheKey";
protected IHttpContextAccessor HttpContextAccessor { get; } protected IHttpContextAccessor HttpContextAccessor { get; }
protected AbpApplicationConfigurationClientProxy ApplicationConfigurationAppService { get; } protected AbpApplicationConfigurationClientProxy ApplicationConfigurationAppService { get; }
@ -46,7 +47,7 @@ public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigu
{ {
string? cacheKey = null; string? cacheKey = null;
var httpContext = HttpContextAccessor?.HttpContext; var httpContext = HttpContextAccessor?.HttpContext;
var itemsKey = string.Format(ApplicationConfigurationDtoCacheKeyFormat, CurrentUser.Id?.ToString("N") ?? "Anonymous"); var itemsKey = string.Format(ApplicationConfigurationDtoCacheKeyFormat, CurrentUser.Id?.ToString("N") ?? "Anonymous", CultureInfo.CurrentUICulture.Name);
if (httpContext != null && httpContext.Items[itemsKey] is string key) if (httpContext != null && httpContext.Items[itemsKey] is string key)
{ {
cacheKey = key; cacheKey = key;
@ -108,7 +109,7 @@ public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigu
{ {
string? cacheKey = null; string? cacheKey = null;
var httpContext = HttpContextAccessor?.HttpContext; var httpContext = HttpContextAccessor?.HttpContext;
var itemsKey = string.Format(ApplicationConfigurationDtoCacheKeyFormat, CurrentUser.Id?.ToString("N") ?? "Anonymous"); var itemsKey = string.Format(ApplicationConfigurationDtoCacheKeyFormat, CurrentUser.Id?.ToString("N") ?? "Anonymous", CultureInfo.CurrentUICulture.Name);
if (httpContext != null && httpContext.Items[itemsKey] is string key) if (httpContext != null && httpContext.Items[itemsKey] is string key)
{ {
cacheKey = key; cacheKey = key;

Loading…
Cancel
Save