You are here

function coffee_flush_caches in Coffee 7.2

Implements hook_flush_caches().

The following caching implemented is lifted from the awesome admin_menu module.

4 calls to coffee_flush_caches()
coffee_menu_alter in ./coffee.module
Implements hook_menu_alter().
coffee_menu_link_delete in ./coffee.module
Implements hook_menu_link_delete().
coffee_menu_link_insert in ./coffee.module
Implements hook_menu_link_insert().
coffee_menu_link_update in ./coffee.module
Implements hook_menu_link_update().

File

./coffee.module, line 200
Coffee primary module file

Code

function coffee_flush_caches($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__, array());

  // $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;
  $cid = 'coffee_commands:';
  if (isset($uid)) {
    $cid .= $uid . ':';
  }

  // db_table_exists() required for SimpleTest.
  if (db_table_exists('cache_coffee')) {
    cache_clear_all(isset($uid) ? $cid : '*', 'cache_coffee', TRUE);
  }
}