Skip to content

Commit

Permalink
Cache lookup of macro by alias
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemegson authored and nul800sebastiaan committed Oct 29, 2019
1 parent 0554b47 commit 8463f1d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Umbraco.Core/Cache/CacheKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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_";
}
}
1 change: 1 addition & 0 deletions src/Umbraco.Web/Cache/MacroCacheRefresher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ internal static string[] GetAllMacroCacheKeys()
return new[]
{
CacheKeys.MacroContentCacheKey, // macro render cache
CacheKeys.MacroFromAliasCacheKey, // lookup macro by alias
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/Umbraco.Web/Macros/MacroRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ private static void UpdateMacroModelProperties(MacroModel model, IDictionary<str

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);

Expand Down

0 comments on commit 8463f1d

Please sign in to comment.