Allow Macro's to be cached differently across variants (#7555)

This commit is contained in:
Marc Goodson
2020-03-26 15:57:15 +00:00
committed by GitHub
parent a0e5b83914
commit 42ddd90fd7
+13 -6
View File
@@ -40,12 +40,18 @@ namespace Umbraco.Web.Macros
#region MacroContent cache
// gets this macro content cache identifier
private string GetContentCacheIdentifier(MacroModel model, int pageId)
private string GetContentCacheIdentifier(MacroModel model, int pageId, string cultureName)
{
var id = new StringBuilder();
var alias = model.Alias;
id.AppendFormat("{0}-", alias);
//always add current culture to the key to allow variants to have different cache results
if (!string.IsNullOrEmpty(cultureName))
{
// are there any unusual culture formats we'd need to handle?
id.AppendFormat("{0}-", cultureName);
}
if (model.CacheByPage)
id.AppendFormat("{0}-", pageId);
@@ -190,7 +196,7 @@ namespace Umbraco.Web.Macros
? macroParams[key]?.ToString() ?? string.Empty
: string.Empty;
}
}
}
#endregion
#region Render/Execute
@@ -221,7 +227,8 @@ namespace Umbraco.Web.Macros
foreach (var prop in macro.Properties)
prop.Value = ParseAttribute(pageElements, prop.Value);
macro.CacheIdentifier = GetContentCacheIdentifier(macro, content.Id);
var cultureName = System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
macro.CacheIdentifier = GetContentCacheIdentifier(macro, content.Id, cultureName);
// get the macro from cache if it is there
var macroContent = GetMacroContentFromCache(macro);
@@ -317,7 +324,7 @@ namespace Umbraco.Web.Macros
private Attempt<MacroContent> ExecuteMacroOfType(MacroModel model, IPublishedContent content)
{
if (model == null) throw new ArgumentNullException(nameof(model));
// ensure that we are running against a published node (ie available in XML)
// that may not be the case if the macro is embedded in a RTE of an unpublished document
@@ -453,9 +460,9 @@ namespace Umbraco.Web.Macros
return value;
}
#endregion
}
}