To cache the result of a macro, enclose the expression into the Cache method.
{% Cache(Documents[NodeAliasPath].Children.Columns("ClassName,DocumentMenuItemHideInNavigation").Where("ClassName = 'cms.menuitem' AND DocumentMenuItemHideInNavigation='False'"))%}
Refer the following documentation for details -
https://docs.xperience.io/k12sp/macro-expressions/caching-the-results-of-macros