From 8463f1db08e91cb25034b5f8b60c818013395fa3 Mon Sep 17 00:00:00 2001 From: Steve Megson Date: Thu, 17 Oct 2019 15:47:16 +0100 Subject: [PATCH] Cache lookup of macro by alias --- src/Umbraco.Core/Cache/CacheKeys.cs | 1 + src/Umbraco.Web/Cache/MacroCacheRefresher.cs | 1 + src/Umbraco.Web/Macros/MacroRenderer.cs | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Core/Cache/CacheKeys.cs b/src/Umbraco.Core/Cache/CacheKeys.cs index e8f93d636a88..b8ee0e97c4de 100644 --- a/src/Umbraco.Core/Cache/CacheKeys.cs +++ b/src/Umbraco.Core/Cache/CacheKeys.cs @@ -11,5 +11,6 @@ public static class CacheKeys public const string TemplateFrontEndCacheKey = "template"; public const string MacroContentCacheKey = "macroContent_"; // used in MacroRenderers + public const string MacroFromAliasCacheKey = "macroFromAlias_"; } } diff --git a/src/Umbraco.Web/Cache/MacroCacheRefresher.cs b/src/Umbraco.Web/Cache/MacroCacheRefresher.cs index a5187db21108..24479b8415cb 100644 --- a/src/Umbraco.Web/Cache/MacroCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/MacroCacheRefresher.cs @@ -99,6 +99,7 @@ internal static string[] GetAllMacroCacheKeys() return new[] { CacheKeys.MacroContentCacheKey, // macro render cache + CacheKeys.MacroFromAliasCacheKey, // lookup macro by alias }; } diff --git a/src/Umbraco.Web/Macros/MacroRenderer.cs b/src/Umbraco.Web/Macros/MacroRenderer.cs index 61b2f0bda3c6..3368def084da 100755 --- a/src/Umbraco.Web/Macros/MacroRenderer.cs +++ b/src/Umbraco.Web/Macros/MacroRenderer.cs @@ -197,7 +197,8 @@ private static void UpdateMacroModelProperties(MacroModel model, IDictionary 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);