Browse Source

add template content to the cache

pull/635/head
cKey 3 years ago
parent
commit
c4f2ba392c
  1. 2
      aspnet-core/modules/localization/LINGYUN.Abp.AspNetCore.Mvc.Localization/LINGYUN/Abp/AspNetCore/Mvc/Localization/LanguageAppService.cs
  2. 2
      aspnet-core/modules/localization/LINGYUN.Abp.AspNetCore.Mvc.Localization/LINGYUN/Abp/AspNetCore/Mvc/Localization/ResourceAppService.cs
  3. 12
      aspnet-core/modules/localization/LINGYUN.Abp.AspNetCore.Mvc.Localization/LINGYUN/Abp/AspNetCore/Mvc/Localization/TextAppService.cs
  4. 7
      aspnet-core/modules/localization/LINGYUN.Abp.AspNetCore.Mvc.Localization/LINGYUN/Abp/AspNetCore/Mvc/Localization/TextDifferenceDto.cs
  5. 1
      aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN.Abp.TextTemplating.Domain.csproj
  6. 21
      aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN/Abp/TextTemplating/AbpTextTemplatingCachingOptions.cs
  7. 6
      aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN/Abp/TextTemplating/AbpTextTemplatingDomainModule.cs
  8. 34
      aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN/Abp/TextTemplating/TemplateContentCacheItem.cs
  9. 52
      aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN/Abp/TextTemplating/TextTemplateCacheItemInvalidator.cs
  10. 41
      aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN/Abp/TextTemplating/TextTemplateContentContributor.cs
  11. 2
      aspnet-core/services/LY.MicroService.identityServer.HttpApi.Host/IdentityServerHttpApiHostModule.Configure.cs
  12. 2
      aspnet-core/services/LY.MicroService.identityServer.HttpApi.Host/appsettings.Development.json
  13. 2
      aspnet-core/services/LY.MicroService.identityServer/IdentityServerModule.Configure.cs
  14. 2
      aspnet-core/services/LY.MicroService.identityServer/appsettings.Development.json

2
aspnet-core/modules/localization/LINGYUN.Abp.AspNetCore.Mvc.Localization/LINGYUN/Abp/AspNetCore/Mvc/Localization/LanguageAppService.cs

@ -27,7 +27,7 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Localization
UiCultureName = l.UiCultureName,
DisplayName = l.DisplayName,
FlagIcon = l.FlagIcon
}).ToList());
}).OrderBy(l => l.CultureName).ToList());
}
}
}

2
aspnet-core/modules/localization/LINGYUN.Abp.AspNetCore.Mvc.Localization/LINGYUN/Abp/AspNetCore/Mvc/Localization/ResourceAppService.cs

@ -26,7 +26,7 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Localization
Name = x.Value.ResourceName,
DisplayName = x.Value.ResourceName,
Description = x.Value.ResourceName,
});
}).OrderBy(l => l.Name);
return Task.FromResult(new ListResultDto<ResourceDto>(resources.ToList()));
}

12
aspnet-core/modules/localization/LINGYUN.Abp.AspNetCore.Mvc.Localization/LINGYUN/Abp/AspNetCore/Mvc/Localization/TextAppService.cs

@ -36,7 +36,8 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Localization
using (CultureHelper.Use(input.CultureName))
{
localizedStrings = localizer.GetAllStrings(true);
localizedStrings = localizer.GetAllStrings(true)
.OrderBy(l => l.Name);
var result = new TextDto
{
@ -57,7 +58,8 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Localization
if (input.ResourceName.IsNullOrWhiteSpace())
{
var filterResources = _localizationOptions.Resources
.WhereIf(!input.Filter.IsNullOrWhiteSpace(), x => x.Value.ResourceName.Contains(input.Filter));
.WhereIf(!input.Filter.IsNullOrWhiteSpace(), x => x.Value.ResourceName.Contains(input.Filter))
.OrderBy(r => r.Value.ResourceName);
foreach (var resource in filterResources)
{
@ -96,7 +98,8 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Localization
using (CultureHelper.Use(cultureName))
{
localizedStrings = localizer.GetAllStrings(true)
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter));
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter))
.OrderBy(l => l.Name);
}
if (Equals(cultureName, targetCultureName))
@ -108,7 +111,8 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Localization
using (CultureHelper.Use(targetCultureName))
{
targetLocalizedStrings = localizer.GetAllStrings(true)
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter));
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter))
.OrderBy(l => l.Name);
}
}

7
aspnet-core/modules/localization/LINGYUN.Abp.AspNetCore.Mvc.Localization/LINGYUN/Abp/AspNetCore/Mvc/Localization/TextDifferenceDto.cs

@ -7,6 +7,11 @@
public string Value { get; set; }
public string ResourceName { get; set; }
public string TargetCultureName { get; set; }
public string TargetValue { get; set; }
public string TargetValue { get; set; }
public int CompareTo(TextDifferenceDto other)
{
return other.ResourceName.CompareTo(ResourceName) ^ other.Key.CompareTo(Key);
}
}
}

1
aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN.Abp.TextTemplating.Domain.csproj

@ -9,6 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Caching" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.Ddd.Domain" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.TextTemplating.Core" Version="$(VoloAbpPackageVersion)" />
</ItemGroup>

21
aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN/Abp/TextTemplating/AbpTextTemplatingCachingOptions.cs

@ -0,0 +1,21 @@
using System;
namespace LINGYUN.Abp.TextTemplating;
public class AbpTextTemplatingCachingOptions
{
/// <summary>
/// 文本模板缓存最小过期时间
/// </summary>
public TimeSpan? MinimumCacheDuration { get; set; }
/// <summary>
/// 文本模板缓存绝对过期时间
/// </summary>
public TimeSpan? MaximumCacheDuration { get; set; }
public AbpTextTemplatingCachingOptions()
{
MinimumCacheDuration = TimeSpan.FromHours(1);
MaximumCacheDuration = TimeSpan.FromDays(30);
}
}

6
aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN/Abp/TextTemplating/AbpTextTemplatingDomainModule.cs

@ -1,11 +1,13 @@
using Volo.Abp.Modularity;
using Volo.Abp.Caching;
using Volo.Abp.Modularity;
using Volo.Abp.TextTemplating;
namespace LINGYUN.Abp.TextTemplating;
[DependsOn(
typeof(AbpTextTemplatingDomainSharedModule),
typeof(AbpTextTemplatingCoreModule))]
typeof(AbpTextTemplatingCoreModule),
typeof(AbpCachingModule))]
public class AbpTextTemplatingDomainModule : AbpModule
{

34
aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN/Abp/TextTemplating/TemplateContentCacheItem.cs

@ -0,0 +1,34 @@
namespace LINGYUN.Abp.TextTemplating;
public class TemplateContentCacheItem
{
private const string CacheKeyFormat = "pn:template-content,n:{0},c:{1}";
public string Name { get; set; }
public string Culture { get; set; }
public string Content { get; set; }
public TemplateContentCacheItem()
{
}
public TemplateContentCacheItem(
string name,
string content,
string culture = null)
{
Name = name;
Content = content;
Culture = culture;
}
public static string CalculateCacheKey(
string name,
string culture = null)
{
return string.Format(
CacheKeyFormat,
name,
culture);
}
}

52
aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN/Abp/TextTemplating/TextTemplateCacheItemInvalidator.cs

@ -0,0 +1,52 @@
using System.Threading.Tasks;
using Volo.Abp.Caching;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events;
using Volo.Abp.EventBus;
using Volo.Abp.MultiTenancy;
namespace LINGYUN.Abp.TextTemplating;
public class TextTemplateCacheItemInvalidator :
ILocalEventHandler<EntityChangedEventData<TextTemplate>>,
ILocalEventHandler<EntityDeletedEventData<TextTemplate>>,
ITransientDependency
{
protected ICurrentTenant CurrentTenant { get; }
protected IDistributedCache<TemplateContentCacheItem> Cache { get; }
public TextTemplateCacheItemInvalidator(IDistributedCache<TemplateContentCacheItem> cache, ICurrentTenant currentTenant)
{
Cache = cache;
CurrentTenant = currentTenant;
}
public async virtual Task HandleEventAsync(EntityChangedEventData<TextTemplate> eventData)
{
await RemoveCacheItemAsync(eventData.Entity);
}
public async virtual Task HandleEventAsync(EntityDeletedEventData<TextTemplate> eventData)
{
await RemoveCacheItemAsync(eventData.Entity);
}
protected async virtual Task RemoveCacheItemAsync(TextTemplate template)
{
var cacheKey = CalculateCacheKey(
template.Name,
template.Culture
);
using (CurrentTenant.Change(template.TenantId))
{
await Cache.RemoveAsync(cacheKey);
}
}
protected virtual string CalculateCacheKey(string name, string culture = null)
{
return TemplateContentCacheItem.CalculateCacheKey(name, culture);
}
}

41
aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN/Abp/TextTemplating/TextTemplateContentContributor.cs

@ -1,5 +1,8 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System.Threading.Tasks;
using Volo.Abp.Caching;
using Volo.Abp.DependencyInjection;
using Volo.Abp.TextTemplating;
@ -7,11 +10,45 @@ namespace LINGYUN.Abp.TextTemplating;
public class TextTemplateContentContributor : ITemplateContentContributor, ITransientDependency
{
protected AbpTextTemplatingCachingOptions TemplatingCachingOptions { get; }
protected IDistributedCache<TemplateContentCacheItem> TextTemplateContentCache { get; }
public TextTemplateContentContributor(
IDistributedCache<TemplateContentCacheItem> textTemplateContentCache,
IOptions<AbpTextTemplatingCachingOptions> templatingCachingOptions)
{
TextTemplateContentCache = textTemplateContentCache;
TemplatingCachingOptions = templatingCachingOptions.Value;
}
public async virtual Task<string> GetOrNullAsync(TemplateContentContributorContext context)
{
var cacheKey = TemplateContentCacheItem.CalculateCacheKey(context.TemplateDefinition.Name, context.Culture);
var cacheItem = await TextTemplateContentCache.GetOrAddAsync(cacheKey,
() => CreateTemplateContentCache(context),
() => CreateTemplateContentCacheOptions());
return cacheItem?.Content;
}
protected async virtual Task<TemplateContentCacheItem> CreateTemplateContentCache(TemplateContentContributorContext context)
{
var repository = context.ServiceProvider.GetRequiredService<ITextTemplateRepository>();
var template = await repository.FindByNameAsync(context.TemplateDefinition.Name, context.Culture);
return template?.Content;
return new TemplateContentCacheItem(
template?.Name,
template?.Content,
template?.Culture);
}
protected DistributedCacheEntryOptions CreateTemplateContentCacheOptions()
{
return new DistributedCacheEntryOptions
{
SlidingExpiration = TemplatingCachingOptions.MinimumCacheDuration,
AbsoluteExpirationRelativeToNow = TemplatingCachingOptions.MaximumCacheDuration,
};
}
}

2
aspnet-core/services/LY.MicroService.identityServer.HttpApi.Host/IdentityServerHttpApiHostModule.Configure.cs

@ -166,7 +166,7 @@ public partial class IdentityServerHttpApiHostModule
Configure<AppUrlOptions>(options =>
{
options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"];
options.Applications["VUE"].RootUrl = configuration["App:VueUrl"];
options.Applications["STS"].RootUrl = configuration["App:StsUrl"];
});
}

2
aspnet-core/services/LY.MicroService.identityServer.HttpApi.Host/appsettings.Development.json

@ -10,7 +10,7 @@
"App": {
"TrackingEntitiesChanged": true,
"SelfUrl": "http://127.0.0.1:30015/",
"VueUrl": "http://127.0.0.1:3100/",
"StsUrl": "http://127.0.0.1:44385/",
"CorsOrigins": "http://127.0.0.1:3100"
},
"ConnectionStrings": {

2
aspnet-core/services/LY.MicroService.identityServer/IdentityServerModule.Configure.cs

@ -207,7 +207,7 @@ public partial class IdentityServerModule
Configure<AppUrlOptions>(options =>
{
options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"];
options.Applications["VUE"].RootUrl = configuration["App:VueUrl"];
options.Applications["STS"].RootUrl = configuration["App:StsUrl"];
options.Applications["MVC"].Urls["EmailVerifyLogin"] = "Account/VerifyCode";
options.Applications["MVC"].Urls["EmailConfirm"] = "Account/EmailConfirm";

2
aspnet-core/services/LY.MicroService.identityServer/appsettings.Development.json

@ -10,7 +10,7 @@
"App": {
"TrackingEntitiesChanged": true,
"SelfUrl": "http://127.0.0.1:44385/",
"VueUrl": "http://127.0.0.1:3100/",
"StsUrl": "http://127.0.0.1:44385/",
"CorsOrigins": "http://127.0.0.1:3100"
},
"AppSelfUrl": "http://127.0.0.1:44385/",

Loading…
Cancel
Save