Skip to content
Browse files

Merge pull request #5 from mattburton/master

Only cache views when debugging is disabled
  • Loading branch information...
2 parents 43670b2 + 0cf807c commit 25a3c5bc5744a82a56bbe3478923758ecbee1389 Martin Rue committed
Showing with 23 additions and 3 deletions.
  1. +11 −1 src/tinyweb.viewengine.razor/RazorCompiler.cs
  2. +12 −2 src/tinyweb.viewengine.spark/SparkCompiler.cs
View
12 src/tinyweb.viewengine.razor/RazorCompiler.cs
@@ -5,6 +5,7 @@
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
+using System.Web;
using System.Web.Configuration;
using System.Web.Razor;
using System.Web.Razor.Generator;
@@ -54,7 +55,11 @@ private static TemplateBase<T> GetCompiledTemplate<T>(T model, string path)
if (!cache.TryGetValue(key, out type))
{
type = GetCompiledType<T>(File.ReadAllText(path));
- cache[key] = type;
+
+ if (CachingIsEnabled())
+ {
+ cache[key] = type;
+ }
}
var instance = (TemplateBase<T>)Activator.CreateInstance(type);
@@ -62,6 +67,11 @@ private static TemplateBase<T> GetCompiledTemplate<T>(T model, string path)
return instance;
}
+ private static bool CachingIsEnabled()
+ {
+ return !HttpContext.Current.IsDebuggingEnabled;
+ }
+
//used to render the master
private static string RenderMasterView<T>(T model, string templatePath, TemplateBase<T> instance)
{
View
14 src/tinyweb.viewengine.spark/SparkCompiler.cs
@@ -2,6 +2,7 @@
using System.Collections.Concurrent;
using System.Configuration;
using System.IO;
+using System.Web;
using Spark;
using Spark.FileSystem;
@@ -29,7 +30,7 @@ public static string Compile<T>(T model, string templatesPath, string templateNa
var output = new StringWriter();
view.RenderView(output);
sparkEngine.ReleaseInstance(view);
-
+
return output.ToString();
}
@@ -74,7 +75,11 @@ private static ISparkViewEntry buildSparkViewEntry(string fullTemplatePath, Spar
if (!cache.ContainsKey(key))
{
entry = sparkEngine.CreateEntry(descriptor);
- cache[key] = entry;
+
+ if (cachingIsEnabled())
+ {
+ cache[key] = entry;
+ }
}
else
{
@@ -83,5 +88,10 @@ private static ISparkViewEntry buildSparkViewEntry(string fullTemplatePath, Spar
return entry;
}
+
+ private static bool cachingIsEnabled()
+ {
+ return !HttpContext.Current.IsDebuggingEnabled;
+ }
}
}

0 comments on commit 25a3c5b

Please sign in to comment.
Something went wrong with that request. Please try again.