The site has a tree menu that contains three steps: Category A ... n -> Subcategory 1 ... n -> Post 1 ... n At the same time, since there can be a dozen two subcategories in one category, each of which has more than ten posts, then building a whole menu as a snake takes quite a lot of resources, if done on the fly, when the page loads. At the same time, the menu is displayed both on the pages of categories and on the pages of posts.
How best to get rid of building a menu on the fly?
Menus can change only if subcategories or posts are added / removed. At the same time, the menu options themselves are as many as the Categories A (which have no parent categories).
It makes sense to generate / change the menu at one point in time, and then store it in the database or somehow cache it?