function drush_cache_clear

4.x cache.drush.inc drush_cache_clear($type = NULL)

Command callback for drush cache-clear.

1 string reference to 'drush_cache_clear'

File

commands/core/cache.drush.inc, line 52

Code

function drush_cache_clear($type = NULL) {
  switch (drush_drupal_major_version()) {
    case 5:
      // clear preprocessor cache
      drupal_clear_css_cache();

      // clear core tables
      $core = array('cache', 'cache_filter', 'cache_menu', 'cache_page');
      $alltables = array_merge($core, module_invoke_all('devel_caches'));
      foreach ($alltables as $table) {
        cache_clear_all('*', $table, TRUE);
      }
      drush_print(dt('Cache cleared.'));
      break;
    case 6:
    case 7:
    default:
      $types = drush_cache_clear_types();
      // Check if the provided type ($type) is a valid cache type.
      if ($type && !key_exists($type, $types)) {
        return drush_set_error(dt("'!type' cache is not a valid cache type", array('!type' => $type)));
      }

      if ($type) {
        drush_op($types[$type]);
        drush_log(dt("'!name' cache was cleared", array('!name' => $type)), 'success');
      }
      else {
        $choice = drush_choice($types, 'Enter a number to choose which cache to clear.', '!key');
        if ($choice !== FALSE) {
          call_user_func($types[$choice]);
          drush_log(dt("'!name' cache was cleared", array('!name' => $choice)), 'success');
        }
      }
      break;
  }
}