Browse Source

Merge pull request #24994 from abpframework/auto-merge/rel-10-0/4393

Merge branch rel-10.1 with rel-10.0
pull/24995/head
Volosoft Agent 4 weeks ago
committed by GitHub
parent
commit
a9364d907d
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 18
      framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClient.cs

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

@ -1,4 +1,5 @@
using System;
using System.Globalization;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Distributed;
@ -14,7 +15,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Client;
public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigurationClient, ITransientDependency
{
private const string ApplicationConfigurationDtoCacheKey = "ApplicationConfigurationDto_CacheKey";
private const string HttpContextItemsCacheKeyFormat = "ApplicationConfigurationDto_{0}_{1}_CacheKey";
protected IHttpContextAccessor HttpContextAccessor { get; }
protected AbpApplicationConfigurationClientProxy ApplicationConfigurationAppService { get; }
@ -46,7 +47,8 @@ public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigu
{
string? cacheKey = null;
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;
}
@ -56,7 +58,7 @@ public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigu
cacheKey = await CreateCacheKeyAsync();
if (httpContext != null)
{
httpContext.Items[ApplicationConfigurationDtoCacheKey] = cacheKey;
httpContext.Items[itemsKey] = cacheKey;
}
}
@ -107,7 +109,8 @@ public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigu
{
string? cacheKey = null;
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;
}
@ -117,7 +120,7 @@ public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigu
cacheKey = AsyncHelper.RunSync(CreateCacheKeyAsync);
if (httpContext != null)
{
httpContext.Items[ApplicationConfigurationDtoCacheKey] = cacheKey;
httpContext.Items[itemsKey] = cacheKey;
}
}
@ -133,4 +136,9 @@ public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigu
{
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