Cache lookup of macro by alias

This commit is contained in:
Steve Megson
2019-10-17 15:47:16 +01:00
committed by Sebastiaan Janssen
parent 0554b47864
commit 8463f1db08
3 changed files with 4 additions and 1 deletions

View File

@@ -11,5 +11,6 @@
public const string TemplateFrontEndCacheKey = "template";
public const string MacroContentCacheKey = "macroContent_"; // used in MacroRenderers
public const string MacroFromAliasCacheKey = "macroFromAlias_";
}
}

View File

@@ -99,6 +99,7 @@ namespace Umbraco.Web.Cache
return new[]
{
CacheKeys.MacroContentCacheKey, // macro render cache
CacheKeys.MacroFromAliasCacheKey, // lookup macro by alias
};
}

View File

@@ -197,7 +197,8 @@ namespace Umbraco.Web.Macros
public MacroContent Render(string macroAlias, IPublishedContent content, IDictionary<string, object> macroParams)
{
var m = _macroService.GetByAlias(macroAlias);
var m = _appCaches.RuntimeCache.GetCacheItem(CacheKeys.MacroFromAliasCacheKey + macroAlias, () => _macroService.GetByAlias(macroAlias));
if (m == null)
throw new InvalidOperationException("No macro found by alias " + macroAlias);