Browse Source

Improve RemoteTenantStore: Reduce AsyncHelper usage.

pull/2422/head
Halil İbrahim Kalkan 7 years ago
parent
commit
5fe88a3b09
  1. 50
      framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteTenantStore.cs

50
framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteTenantStore.cs

@ -85,12 +85,58 @@ namespace Volo.Abp.AspNetCore.Mvc.Client
public TenantConfiguration Find(string name)
{
return AsyncHelper.RunSync(() => FindAsync(name));
var cacheKey = CreateCacheKey(name);
var httpContext = HttpContextAccessor?.HttpContext;
if (httpContext != null && httpContext.Items[cacheKey] is TenantConfiguration tenantConfiguration)
{
return tenantConfiguration;
}
tenantConfiguration = Cache.GetOrAdd(
cacheKey,
() => AsyncHelper.RunSync(async () => CreateTenantConfiguration(await Proxy.Service.FindTenantByNameAsync(name))),
() => new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow =
TimeSpan.FromMinutes(5) //TODO: Should be configurable.
}
);
if (httpContext != null)
{
httpContext.Items[cacheKey] = tenantConfiguration;
}
return tenantConfiguration;
}
public TenantConfiguration Find(Guid id)
{
return AsyncHelper.RunSync(() => FindAsync(id));
var cacheKey = CreateCacheKey(id);
var httpContext = HttpContextAccessor?.HttpContext;
if (httpContext != null && httpContext.Items[cacheKey] is TenantConfiguration tenantConfiguration)
{
return tenantConfiguration;
}
tenantConfiguration = Cache.GetOrAdd(
cacheKey,
() => AsyncHelper.RunSync(async () => CreateTenantConfiguration(await Proxy.Service.FindTenantByIdAsync(id))),
() => new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow =
TimeSpan.FromMinutes(5) //TODO: Should be configurable.
}
);
if (httpContext != null)
{
httpContext.Items[cacheKey] = tenantConfiguration;
}
return tenantConfiguration;
}
protected virtual TenantConfiguration CreateTenantConfiguration(FindTenantResultDto tenantResultDto)

Loading…
Cancel
Save