diff --git a/umbraco.MacroEngines.Juno/RazorEngine.cs b/umbraco.MacroEngines.Juno/RazorEngine.cs
index 17422c7f79..a298af799b 100644
--- a/umbraco.MacroEngines.Juno/RazorEngine.cs
+++ b/umbraco.MacroEngines.Juno/RazorEngine.cs
@@ -40,7 +40,7 @@ namespace umbraco.MacroEngines
try
{
string parsedResult;
- if (!GetResult("RazorValidation", code, currentPage, out parsedResult)) {
+ if (!GetResult(null, code, currentPage, out parsedResult)) {
errorMessage = parsedResult;
return false;
}
@@ -68,11 +68,26 @@ namespace umbraco.MacroEngines
: loadScript(IOHelper.MapPath(SystemDirectories.Python + "/" + macro.ScriptName));
string parsedResult;
GetResult(macro.CacheIdentifier, template, currentPage, out parsedResult);
+
+ // if it's a file we'll monitor changes to ensure that any updates to the file clears the cache
+ if (String.IsNullOrEmpty(macro.ScriptCode)) {
+ FileMonitor.Listen(SystemDirectories.Python + "/" + macro.ScriptName, action => RazorEngine.ClearRazorCompilationCache());
+ }
+
return parsedResult;
}
#endregion
+ ///
+ /// This clears all compiled razor scripts, thus ensures that changes made to files or scripts causes a recompilation
+ ///
+ public static void ClearRazorCompilationCache()
+ {
+ Razor.SetTemplateBaseType(typeof(HtmlTemplateBase<>));
+ Razor.SetTemplateBaseType(typeof(UmbracoTemplateBase<>));
+ }
+
private bool GetResult(string cacheIdentifier, string template, INode currentPage, out string result)
{
try
diff --git a/umbraco/businesslogic/IO/FileMonitor.cs b/umbraco/businesslogic/IO/FileMonitor.cs
new file mode 100644
index 0000000000..257e8622d5
--- /dev/null
+++ b/umbraco/businesslogic/IO/FileMonitor.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Web;
+using System.Web.Caching;
+using System.Web.Hosting;
+
+namespace umbraco.IO
+{
+ ///
+ /// This class can be used to monitor file changes and update accordingly. This is copied
+ /// from http://haacked.com/archive/2010/01/17/editable-routes.aspx and based on work in Dynamic Data
+ ///
+ public class FileMonitor
+ {
+ private FileMonitor(Action changeCallback)
+ : this(HostingEnvironment.VirtualPathProvider, changeCallback)
+ {
+ }
+
+ private FileMonitor(VirtualPathProvider vpp,
+ Action changeCallback)
+ {
+ _vpp = vpp;
+ _changeCallback = changeCallback;
+ }
+
+ VirtualPathProvider _vpp;
+ Action _changeCallback;
+
+ // When the file at the given path changes,
+ // we'll call the supplied action.
+ public static void Listen(string virtualPath, Action action)
+ {
+ var notifier = new FileMonitor(action);
+ notifier.ListenForChanges(virtualPath);
+ }
+
+ void ListenForChanges(string virtualPath)
+ {
+ // Get a CacheDependency from the BuildProvider,
+ // so that we know anytime something changes
+ var virtualPathDependencies = new List();
+ virtualPathDependencies.Add(virtualPath);
+ CacheDependency cacheDependency = _vpp.GetCacheDependency(
+ virtualPath, virtualPathDependencies, DateTime.UtcNow);
+ HttpRuntime.Cache.Insert(virtualPath /*key*/,
+ virtualPath /*value*/,
+ cacheDependency,
+ Cache.NoAbsoluteExpiration,
+ Cache.NoSlidingExpiration,
+ CacheItemPriority.NotRemovable,
+ new CacheItemRemovedCallback(OnConfigFileChanged));
+ }
+
+ void OnConfigFileChanged(string key, object value,
+ CacheItemRemovedReason reason)
+ {
+ // We only care about dependency changes
+ if (reason != CacheItemRemovedReason.DependencyChanged)
+ return;
+
+ _changeCallback(key);
+
+ // Need to listen for the next change
+ ListenForChanges(key);
+ }
+ }
+}
diff --git a/umbraco/businesslogic/umbraco.businesslogic.csproj b/umbraco/businesslogic/umbraco.businesslogic.csproj
index 42a6e40bbc..ebfb76d9ad 100644
--- a/umbraco/businesslogic/umbraco.businesslogic.csproj
+++ b/umbraco/businesslogic/umbraco.businesslogic.csproj
@@ -158,6 +158,7 @@
Code
+