I was caching some goodies related to the menu, and putting it in the 'cache_menu' bin, assuming they would get cleared whenever someones edits the menu.

cache_set($cachekey, $mymenu, 'cache_menu', CACHE_TEMPORARY);

When I edit the menu, it isn't cleared. When is it cleared, then?

In what sense is it different from the cache bin?

1 Answer 1


Looking at menu_link_save(), you will see that it calls menu_cache_clear() to clear only the cache of the menu the menu item belongs to. Other entries in the menu cache are not cleared.

The entire menu cache is only cleared when menu_cache_clear_all() is called directly (eg. by menu_enable(), which runs whenever a module is enabled) or indirectly (often through menu_rebuild() or drupal_flush_all_caches()).

If I were you, I would store my own data in the default 'cache' bin. I consider the menu cache to be private to the menu system; I don't want to touch it and accidentally mess something up. To clear my cache data at the right moment, I would implement hook_meu_link_insert() and/or hook_meu_link_update() and clear/rebuild my cache data from there.

  • did that, works (hook must be in a module, not in a theme). used cache_clear_all($cachekeystart, 'cache', true); drupal_set_message('Custom Menu cache cleared'); on insert, update and delete
    – commonpike
    Jan 12, 2017 at 21:52
  • 1
    Thanks for the feedback. That sounds right, if I'm not mistaken, only alter hooks (eg. hook_form_alter) can live in both themes and modules. Jan 12, 2017 at 22:41
  • Alters, preprocess, and process hooks can be called from both.
    – mpdonadio
    Jan 13, 2017 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.