Fixes issues with macro caching, Work items: 29891
This commit is contained in:
@@ -375,17 +375,31 @@ namespace umbraco
|
||||
model.CacheIdentifier = getCacheGuid(model, pageElements, pageId);
|
||||
|
||||
if (model.CacheDuration > 0)
|
||||
{
|
||||
if (cacheMacroAsString(model))
|
||||
{
|
||||
macroHtml = macroCache["macroHtml_" + model.CacheIdentifier] as String;
|
||||
|
||||
if (!String.IsNullOrEmpty(macroHtml))
|
||||
{
|
||||
macroHtml = macroCache["macroHtml_" + model.CacheIdentifier] as String;
|
||||
HttpContext.Current.Trace.Write("renderMacro", "Content loaded from cache ('" + model.CacheIdentifier + "')...");
|
||||
HttpContext.Current.Trace.Write("renderMacro", "Macro Content loaded from cache ('" + model.CacheIdentifier + "')...");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (macroCache["macroControl_" + model.CacheIdentifier] != null)
|
||||
{
|
||||
MacroCacheContent cacheContent = (MacroCacheContent)macroCache["macroControl_" + model.CacheIdentifier];
|
||||
macroControl = cacheContent.Content;
|
||||
macroControl.ID = cacheContent.ID;
|
||||
HttpContext.Current.Trace.Write("renderMacro", "Macro Control loaded from cache ('" + model.CacheIdentifier + "')...");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(macroHtml))
|
||||
if (String.IsNullOrEmpty(macroHtml) && macroControl == null)
|
||||
{
|
||||
int macroType = model.MacroType != MacroTypes.Unknown ? (int)model.MacroType : MacroType;
|
||||
switch (macroType)
|
||||
@@ -474,6 +488,9 @@ namespace umbraco
|
||||
if (!model.CacheByMember || (model.CacheByMember && Member.GetCurrentMember() != null))
|
||||
{
|
||||
if (macroControl != null)
|
||||
{
|
||||
// NH: Scripts and XSLT can be generated as strings, but not controls as page events wouldn't be hit (such as Page_Load, etc)
|
||||
if (cacheMacroAsString(model))
|
||||
{
|
||||
using (var sw = new StringWriter())
|
||||
{
|
||||
@@ -494,10 +511,18 @@ namespace umbraco
|
||||
macroControl = new LiteralControl(sw.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
macroCache.Insert("macroControl_" + model.CacheIdentifier, new MacroCacheContent(macroControl, macroControl.ID), null,
|
||||
DateTime.Now.AddSeconds(model.CacheDuration), TimeSpan.Zero, CacheItemPriority.Low,
|
||||
null);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (macroControl == null)
|
||||
{
|
||||
macroControl = new LiteralControl(macroHtml);
|
||||
}
|
||||
@@ -505,6 +530,11 @@ namespace umbraco
|
||||
return macroControl;
|
||||
}
|
||||
|
||||
private bool cacheMacroAsString(MacroModel model)
|
||||
{
|
||||
return model.MacroType == MacroTypes.XSLT || model.MacroType == MacroTypes.Python;
|
||||
}
|
||||
|
||||
public static XslCompiledTransform getXslt(string XsltFile)
|
||||
{
|
||||
if (HttpRuntime.Cache["macroXslt_" + XsltFile] != null)
|
||||
|
||||
Reference in New Issue
Block a user