diff --git a/src/Framework/Framework/Compilation/DefaultControlBuilderFactory.cs b/src/Framework/Framework/Compilation/DefaultControlBuilderFactory.cs
index bc2a015642..c4a3685151 100644
--- a/src/Framework/Framework/Compilation/DefaultControlBuilderFactory.cs
+++ b/src/Framework/Framework/Compilation/DefaultControlBuilderFactory.cs
@@ -181,6 +181,13 @@ void editCompilationException(DotvvmCompilationException ex)
}
}
+ /// Removes an old entry from the cache, forcing a recompilation. If loading of this view is already running
+ public void InvalidateCache(string virtualPath)
+ {
+ this.markupFiles.TryRemove(virtualPath, out _);
+ this.controlBuilders.TryRemove(virtualPath, out _);
+ }
+
public void LoadCompiledViewsAssembly(string filePath)
{
var assembly = TryFindAssembly(filePath);
diff --git a/src/Framework/Framework/Compilation/DotvvmViewCompilationService.cs b/src/Framework/Framework/Compilation/DotvvmViewCompilationService.cs
index 1a9ab1cca6..a88597dbe0 100644
--- a/src/Framework/Framework/Compilation/DotvvmViewCompilationService.cs
+++ b/src/Framework/Framework/Compilation/DotvvmViewCompilationService.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
@@ -105,10 +105,11 @@ public async Task CompileAll(bool buildInParallel = true, bool forceRecomp
var discoveredMasterPages = new ConcurrentDictionary();
- Func compilationTaskFactory = t => new Action(() => {
- BuildView(t, out var masterPage);
- if (masterPage != null && masterPage.Status == CompilationState.None) discoveredMasterPages.TryAdd(masterPage.VirtualPath, masterPage);
- });
+ var compilationTaskFactory = (DotHtmlFileInfo t) => () => {
+ BuildView(t, forceRecompile, out var masterPage);
+ if (masterPage != null && masterPage.Status == CompilationState.None)
+ discoveredMasterPages.TryAdd(masterPage.VirtualPath, masterPage);
+ };
var compileTasks = filesToCompile.Select(compilationTaskFactory).ToArray();
await ExecuteCompileTasks(compileTasks, buildInParallel);
@@ -144,13 +145,19 @@ private async Task ExecuteCompileTasks(Action[] compileTasks, bool buildInParall
}
}
- public bool BuildView(DotHtmlFileInfo file, out DotHtmlFileInfo? masterPage)
+ public bool BuildView(DotHtmlFileInfo file, out DotHtmlFileInfo? masterPage) =>
+ BuildView(file, false, out masterPage);
+ public bool BuildView(DotHtmlFileInfo file, bool forceRecompile, out DotHtmlFileInfo? masterPage)
{
masterPage = null;
if (file.Status != CompilationState.NonCompilable)
{
try
{
+ if (forceRecompile)
+ // TODO: next major version - add method to interface
+ (controlBuilderFactory as DefaultControlBuilderFactory)?.InvalidateCache(file.VirtualPath);
+
var pageBuilder = controlBuilderFactory.GetControlBuilder(file.VirtualPath);
using var scopedServiceProvider = dotvvmConfiguration.ServiceProvider.CreateScope(); // dependencies that are configured as scoped cannot be resolved from root service provider
diff --git a/src/Framework/Framework/Compilation/IControlBuilderFactory.cs b/src/Framework/Framework/Compilation/IControlBuilderFactory.cs
index 815987c39c..7fed27c911 100644
--- a/src/Framework/Framework/Compilation/IControlBuilderFactory.cs
+++ b/src/Framework/Framework/Compilation/IControlBuilderFactory.cs
@@ -6,5 +6,7 @@ namespace DotVVM.Framework.Compilation
public interface IControlBuilderFactory
{
(ControlBuilderDescriptor descriptor, Lazy builder) GetControlBuilder(string virtualPath);
+ // TODO: next major version
+ // void InvalidateCache(string virtualPath);
}
}