Browse Source

Introduce ApplicationConfigurationCache

pull/5399/head
Halil İbrahim Kalkan 6 years ago
parent
commit
3cb1b12946
  1. 20
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ApplicationConfigurationCache.cs
  2. 37
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCachedApplicationConfigurationClient.cs
  3. 0
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCurrentPrincipalAccessor.cs
  4. 1
      framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo/Abp/AspNetCore/Mvc/Client/RemoteLocalizationContributor.cs

20
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ApplicationConfigurationCache.cs

@ -0,0 +1,20 @@
using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.WebAssembly
{
public class ApplicationConfigurationCache : ISingletonDependency
{
protected ApplicationConfigurationDto Configuration { get; set; }
public virtual ApplicationConfigurationDto Get()
{
return Configuration;
}
internal void Set(ApplicationConfigurationDto configuration)
{
Configuration = configuration;
}
}
}

37
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCachedApplicationConfigurationClient.cs

@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations;
using Volo.Abp.AspNetCore.Mvc.Client;
using Volo.Abp.DependencyInjection;
@ -11,43 +10,41 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly
{
protected IHttpClientProxy<IAbpApplicationConfigurationAppService> Proxy { get; }
protected IMemoryCache Cache { get; }
protected ApplicationConfigurationCache Cache { get; }
public WebAssemblyCachedApplicationConfigurationClient(
IHttpClientProxy<IAbpApplicationConfigurationAppService> proxy,
IMemoryCache cache)
ApplicationConfigurationCache cache)
{
Proxy = proxy;
Cache = cache;
}
public async Task InitializeAsync()
public virtual async Task InitializeAsync()
{
await GetAsync();
Cache.Set(await Proxy.Service.GetAsync());
}
public async Task<ApplicationConfigurationDto> GetAsync()
public virtual Task<ApplicationConfigurationDto> GetAsync()
{
return await Cache.GetOrCreateAsync(
CreateCacheKey(),
e => Proxy.Service.GetAsync()
);
return Task.FromResult(GetConfigurationByChecking());
}
public ApplicationConfigurationDto Get()
public virtual ApplicationConfigurationDto Get()
{
var cacheKey = CreateCacheKey();
if(Cache.TryGetValue(cacheKey, out ApplicationConfigurationDto value))
{
return value;
}
throw new AbpException($"Should initialize the {nameof(ICachedApplicationConfigurationClient)} before getting the value!");
return GetConfigurationByChecking();
}
protected virtual string CreateCacheKey()
private ApplicationConfigurationDto GetConfigurationByChecking()
{
return $"ApplicationConfiguration";
var configuration = Cache.Get();
if (configuration == null)
{
throw new AbpException(
$"{nameof(WebAssemblyCachedApplicationConfigurationClient)} should be initialized before using it.");
}
return configuration;
}
}
}

0
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCurrentUser.cs → framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCurrentPrincipalAccessor.cs

1
framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo/Abp/AspNetCore/Mvc/Client/RemoteLocalizationContributor.cs

@ -4,7 +4,6 @@ using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Localization;
using Volo.Abp.Threading;
namespace Volo.Abp.AspNetCore.Mvc.Client
{

Loading…
Cancel
Save