Problem
info hooks have one major design gap: if provided info changes, how to invalidate cached dependent data?
(in dataflow speak: we have only a pull and no push mechanism.)
examples:
* if hook_menu() info changes you do a menu_rebuild() (and pray that no other modules caches hook_menu() info)
* commerce_custom_line_items.module implements hook_commerce_line_items() and hardcodes a cache clear mechanism on behalf of commerce_line_items.module
Clarification
some hooks like hook_menu() are not explicitly named hook_foo_info(), but for this issue we call them info hooks too. this might change with
#1751240: Fix naming pattern of info hooks β
.
Proposed solution
Invoking hook_foo_info_change() notifies all modules that
* hook_foo_info() data changed
* all caches need to be cleared
* and maybe other actions taken
in contrast to today's solution to e.g. calling menu_rebuild() any module can listen to this ntification.
Example
if dynamic_foo_provider.module implementing hook_foo_info() changes their info
then it calls
// invoke hook_foo_info_change() and clear dependent caches
module_invoke_all('foo_info_change', 'dynamic_foo_provider');
and any foo_info_consumer.module can invalidate its cache like this
/**
* Implements hook_foo_info_change()
*
* clears the cache when provided info changes
* @see:http://drupal.org/node/1446808
*
* TODO: for now we clear our whole cache if some module announces an info change
* we might use $module and make this more granular later
*/
function foo_info_consumer_foo_info_change($module) {
foo_info_consumer_clear_foo_cache();
}
About $module
The $module parameter can help to partially clear cache.