How to cache macro that return bunch of data

benyamin jain asked on February 13, 2022 14:59

Hi how is it possible to cache result of Documents[NodeAliasPath].Children.Columns("ClassName,DocumentMenuItemHideInNavigation").Where("ClassName = 'cms.menuitem' AND DocumentMenuItemHideInNavigation='False'") macro. to reduce database access.

say we use this macro in hierarchical viewer.

With best regards

Correct Answer

vasu yerramsetti answered on March 2, 2022 03:09

benyamin jain - Yes. It reduces database hit. Please use the following debugging options to check how your request is working -

https://docs.xperience.io/k12sp/configuring-kentico/managing-sites/configuring-settings-for-sites/settings-system/settings-debug

1 votesVote for this answer Unmark Correct answer

Recent Answers


vasu yerramsetti answered on February 13, 2022 17:38

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

0 votesVote for this answer Mark as a Correct answer

benyamin jain answered on February 15, 2022 18:51

Thanks vasu

as we use this inside hierarchical viewer transformations, is this decrease database access?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.