To construct a WordPress menu, WordPress makes multiple queries to the database to generate the menu content.
If you are using advanced UberMenu features like Dynamic Items, Dynamically Inherited Featured Images, or Menu Segments, there can be additional database queries – and these queries can add up.
The first line of optimization is to configure your menu efficiently (use ‘Assign Image on Save’ when possible, don’t use Dynamic Items unnecessarily), but once you’ve got your menu in place, you can further reduce your database load by caching the menu output.
The WP Menu Cache plugin uses the WordPress Transients API to save the generated menu markup in the database, so that instead of regenerating the entire menu on each page load, the menu is cached and retrieved in a single query instead.
Caching Strategies
There are some pitfalls to caching WordPress menus – namely, that dynamic properties like current menu items won’t work when cached globally. While there isn’t a universal solution, WP Menu Cache offers several caching strategies which can work for you:
Global
Cache one version of the menu for all pages. In this case, you’ll want to disable any current item styling, and there won’t be any indicator as to the current page. For some sites, this works just fine.
Selected Pages Only
WP Menu Cache allows you to choose specific pages to cache the menu for, while other pages will not be cached. This can work well for sites with high traffic on specific pages. Each page’s menu will be cached independently, so current menu items will work properly.
Selected Pages with Global Fallback
With this strategy, you can again select the pages whose menus will be cached independently. All other pages on the site will be served a common globally cached menu.
All Pages Individually
This strategy will automatically create an independent cache for each page on your site. For relatively small sites, this will work well, as it will maintain dynamic properties like current menu items for each page while still leveraging the cache. However, if you have many pages on your site, you probably won’t want to use this strategy as you’ll be adding extra transients to the database for every page on your site, and this can add up quickly.
Using WP Menu Cache with server caches
If you are using a cache like W3 Total Cache or WP Super Cache, there isn’t much gain to using WP Menu Cache on the front end – the entire page is already cached statically. And in this case, a server cache will do a better job than WP Menu Cache because there is no database query at all. They can live together in harmony, however.
Server caches, however, generally only apply to logged-out users. Since logged-in users see customized content, their pages are generally not cached. However, WP Menu Cache will still work for logged in users, so you can see efficiency gains there.
The upshot is that if you are using a server cache and do not have logged in users, you probably don’t need WP Menu Cache. On the other hand, if you have a lot of logged in users, using WP Menu Cache can speed up your site for logged in users even if you are already using a server cache
Caveats
If you are using user-specific dynamic menu items (for example, certain Conditions from the Conditionals Extension), this plugin will break that functionality, as it will cache the state of the first page load and any changes will not be seen. There is no per-user cache.