The idea of a snippet is very simple. Often you want to make a menu on the site, which remains unchanged on all pages. Only the CSS class of the active menu item changes. Why do we need to make inquiries in the database on each page and generate a menu if we only need to change the CSS class? And if this is a large menu with drop-down sublevels, too many resources can be spent on its generation. Snippet
menuCaching allows
you to save the server from this extra work.

Snippet description
Snippet allows you not to generate a menu for each page separately just in order to put the CSS class on the active menu item.
The menu is generated only once for the entire site, but the active items are marked.
')
Usage example
[[menuCaching? &snippetToCache=`Wayfinder` &cacheSuffix=`top_menu` &contexts=`web` &startId=`0` &level=`1` &hereClass=`active` &rowTpl=`@CODE: <li class="[[+wf.classnames]] {{active[[+id]]}}"><a href="[[+wf.link]]">[[+wf.linktext]]</a></li>` ]]
It is recommended to create a set of parameters (for example, "top_menu") in order to, again, save the MODX parser from unnecessary work:
[[menuCaching@top_menu]]
What is happening here, I think you guessed it. The menu cache is stored as follows:
<ul> <li class="first {{active1}}"><a href=""> 1</a></li> <li class=" {{active2}}"><a href=""> 2</a></li> <li class="last {{active3}}"><a href=""> 3</a></li> </ul>
It remains only to replace the labels of the type {{active1}} with the class of the active element, and remove the rest, which the snippet does. A snippet includes a plugin that clears the cache when you click the "Refresh website" button in the admin panel.
An important snippet parameter is
cacheSuffix . The example creates a cache for the entire site, but you can create a cache for individual parent categories, and within one category everything will be taken from the cache:
&cacheSuffix=`[[*parent]]`
This snippet can be used not only for menus, but for example for different sliders, etc. blocks that do not change on the site on different pages.
Snippet
menuCaching in the MODX repository:
http://modx.com/extras/package/menucachingAdded byTest results with a large menu. Calls of both snippets are uncached, i.e. [[! snippet]] (for the test, in reality it is necessary to cache).
WayfinderThe first call to any of the pages where there is a menu:
2.5815 sec.Go to any other page with the same menu:
2.4566 sec. (Ie vaunted cacheResults doesn't help)
Updating the page:
1.0021 sec. (only in this case, cacheResults saves)
Same Wayfinder, via menuCachingThe first call to any of the pages where there is a menu:
2.4842 seconds. (within the limits of error, of course there is no difference)
Go to any other page with the same menu:
0.7008 sec. (the result is the same, but the time is different)
Refreshing the page:
0.4187 sec.