Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable reader cache in the development environment. #20638

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,23 @@ public class LocalizedTemplateContentReaderFactory : ILocalizedTemplateContentRe
protected IVirtualFileProvider VirtualFileProvider { get; }
protected ConcurrentDictionary<string, ILocalizedTemplateContentReader> ReaderCache { get; }
protected SemaphoreSlim SyncObj;
protected IAbpHostEnvironment AbpHostEnvironment { get; }

public LocalizedTemplateContentReaderFactory(IVirtualFileProvider virtualFileProvider)
public LocalizedTemplateContentReaderFactory(IVirtualFileProvider virtualFileProvider, IAbpHostEnvironment abpHostEnvironment)
{
VirtualFileProvider = virtualFileProvider;
AbpHostEnvironment = abpHostEnvironment;
ReaderCache = new ConcurrentDictionary<string, ILocalizedTemplateContentReader>();
SyncObj = new SemaphoreSlim(1, 1);
}

public virtual async Task<ILocalizedTemplateContentReader> CreateAsync(TemplateDefinition templateDefinition)
{
if (AbpHostEnvironment.IsDevelopment())
{
return await CreateInternalAsync(templateDefinition);
}

if (ReaderCache.TryGetValue(templateDefinition.Name, out var reader))
{
return reader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public RazorLocalizedTemplateContentReaderFactory_Tests()
LocalizedTemplateContentReaderFactory = new LocalizedTemplateContentReaderFactory(
new PhysicalFileVirtualFileProvider(
new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(),
"Volo", "Abp", "TextTemplating", "Razor"))));
"Volo", "Abp", "TextTemplating", "Razor"))),
GetRequiredService<IAbpHostEnvironment>());

WelcomeEmailEnglishContent = "@inherits Volo.Abp.TextTemplating.Razor.RazorTemplatePageBase<Volo.Abp.TextTemplating.Razor.RazorTemplateRendererProvider_Tests.WelcomeEmailModel>" +
Environment.NewLine +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public ScribanLocalizedTemplateContentReaderFactory_Tests()
LocalizedTemplateContentReaderFactory = new LocalizedTemplateContentReaderFactory(
new PhysicalFileVirtualFileProvider(
new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(),
"Volo", "Abp", "TextTemplating", "Scriban"))));
"Volo", "Abp", "TextTemplating", "Scriban"))),
GetRequiredService<IAbpHostEnvironment>());

WelcomeEmailEnglishContent = "Welcome {{model.name}} to the abp.io!";
WelcomeEmailTurkishContent = "Merhaba {{model.name}}, abp.io'ya hoşgeldiniz!";
Expand Down
Loading