I have a post_type "products" which has both "Category" and "Brand" taxonomies. Each product has exactly 1 Category, and exactly 1 Brand.

I would like to display a menu which first lists the Categories as the top-level menu, and then lists the Brands contained in each as a Sub-Menu.

Each Sub-Menu should only display the Brands which are associated with Products in that specific top-level Category.

The links in the Sub-Menu should then go to a page that only shows Products in the selected Brand and Category... but I think I can figure this part out with wp_query. Mostly I am confused on the Menu issue.

The function, after having deleted the cache, calls category_brand_menu_data() so cache is built again, and when function will be called from frontend, output will be taken from cache being well performant.

Now we have a performant function that retrieve terms associations, and we only need a function that use retrieved data to display the menu:

Haha wow. Thanks for the incredibly in-depth response. This certainly turned out to be a much more complex problem than I originally thought. Luckily, I figured out a straightforward way to do it with one DB query, which I've posted below if you're interested. You've definitely earned the bounty though, thanks again.
–
CharlesApr 22 '14 at 18:19

Nice query. But hardcoding that way means that it's not reusable, and if in future you want to do same thing with another taxonomy you have to write duplicate code.. I think that with a little effort you can make it flexible. Also have you tested query performance? Mind to implement some caching system if you haven't already...
–
gmazzapApr 23 '14 at 14:53