function admin_menu_cache_flush in Administration menu 8.3
Implements hook_cache_flush().
Flushes client-side caches.
@todo Move custom cache flushing into an own function.
Parameters
int $uid: (optional) A user ID to limit the cache flush to.
6 calls to admin_menu_cache_flush()
- admin_menu_form_alter_flush_cache_submit in ./
admin_menu.module - Form submission handler to flush Administration menu caches.
- admin_menu_menu_alter in ./
admin_menu.module - Implements hook_menu_alter().
- admin_menu_menu_link_delete in ./
admin_menu.module - Implements hook_menu_link_delete().
- admin_menu_menu_link_insert in ./
admin_menu.module - Implements hook_menu_link_insert().
- admin_menu_menu_link_update in ./
admin_menu.module - Implements hook_menu_link_update().
File
- ./
admin_menu.module, line 775 - Render an administrative menu as a dropdown menu at the top of the window.
Code
function admin_menu_cache_flush($uid = NULL) {
// A call to menu_rebuild() will trigger potentially thousands of calls into
// menu_link_save(), for which admin_menu has to implement the corresponding
// CRUD hooks, in order to take up any menu link changes, since any menu link
// change could affect the admin menu (which essentially is an aggregate) and
// since there is no other way to get notified about stale caches. The cache
// only needs to be flushed once though, so we prevent a ton of needless
// subsequent calls with this static.
// @see http://drupal.org/node/918538
$was_flushed =& drupal_static(__FUNCTION__, []);
// $uid can be NULL. PHP automatically converts that into '' (empty string),
// which is different to uid 0 (zero).
if (isset($was_flushed[$uid])) {
return;
}
$was_flushed[$uid] = TRUE;
$tags = [
'admin_menu' => TRUE,
];
// When a user ID was passed, limit cache flushes to that.
if (isset($uid)) {
$tags['user'] = $uid;
}
// Flush cached output of admin_menu.
cache('menu')
->invalidateTags($tags);
// Flush client-side cache hashes.
drupal_static_reset('admin_menu_cache_get');
cache('admin_menu')
->invalidateTags($tags);
// Return value is only used by drupal_flush_all_caches().
return [
'admin_menu',
];
}