6

In Drupal 8 we have the command drush cr which is the new version of the deprecated drush cc all. However we had drush cc menu and some more specific cache clear commands. If I try to execute them, I get weird symfony error.

What I want to achieve: Find the replacement commands for drush cc (specific cache) in Drupal 8.

What I have checked/tried already: The documentation is a bit scarce: https://drushcommands.com/drush-8x/cache/cache-clear/

Manually typing all types of commands like drush cr menu, etc. They don't seem to work.

Regards, Oleg

  • What weird error? drush cc and many of its more specific cache clear commands still exist, for example drush cc render. – Berdir Mar 10 '17 at 15:08
6

drush is not ready for that right now (as far as I know), so you'll need to write custom drush-scripts or do some other execution. drush cr rebuilds the whole cache, drush cc is not working with drupal8.

the method drupal_flush_all_caches shows how to flush all core caches.

$module_handler = \Drupal::moduleHandler();
  // Flush all persistent caches.
  // This is executed based on old/previously known information, which is
  // sufficient, since new extensions cannot have any primed caches yet.
  $module_handler->invokeAll('cache_flush');
  foreach (Cache::getBins() as $service_id => $cache_backend) {
    $cache_backend->deleteAll();
  }

  // Flush asset file caches.
  \Drupal::service('asset.css.collection_optimizer')->deleteAll();
  \Drupal::service('asset.js.collection_optimizer')->deleteAll();
  _drupal_flush_css_js();

  // Reset all static caches.
  drupal_static_reset();

  // Invalidate the container.
  \Drupal::service('kernel')->invalidateContainer();

  // Wipe the Twig PHP Storage cache.
  PhpStorageFactory::get('twig')->deleteAll();

  // Rebuild module and theme data.
  $module_data = system_rebuild_module_data();
  /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */
  $theme_handler = \Drupal::service('theme_handler');
  $theme_handler->refreshInfo();
  // In case the active theme gets requested later in the same request we need
  // to reset the theme manager.
  \Drupal::theme()->resetActiveTheme();


  // Rebuild and reboot a new kernel. A simple DrupalKernel reboot is not
  // sufficient, since the list of enabled modules might have been adjusted
  // above due to changed code.
  $files = array();
  foreach ($module_data as $name => $extension) {
    if ($extension->status) {
      $files[$name] = $extension;
    }
  }
  \Drupal::service('kernel')->updateModules($module_handler->getModuleList(), $files);
  // New container, new module handler.
  $module_handler = \Drupal::moduleHandler();

  // Ensure that all modules that are currently supposed to be enabled are
  // actually loaded.
  $module_handler->loadAll();

  // Rebuild all information based on new module data.
  $module_handler->invokeAll('rebuild');

  // Clear all plugin caches.
  \Drupal::service('plugin.cache_clearer')->clearCachedDefinitions();

  // Rebuild the menu router based on all rebuilt data.
  // Important: This rebuild must happen last, so the menu router is guaranteed
  // to be based on up to date information.
  \Drupal::service('router.builder')->rebuild();

  // Re-initialize the maintenance theme, if the current request attempted to
  // use it. Unlike regular usages of this function, the installer and update
  // scripts need to flush all caches during GET requests/page building.
  if (function_exists('_drupal_maintenance_theme')) {
    \Drupal::theme()->resetActiveTheme();
    drupal_maintenance_theme();
  }
  • Thanks for the answer then :) I guess we will have to wait for it. Until then we can write specific scripts. – O V Mar 10 '17 at 10:53
3

You can use DrupalConsole cache:rebuild command and use the interactive mode to select from the list the cache to clear.

drupal cache:rebuild

You can also use the command alias cr

drupal cr

If you know the cache you are trying to clear try passing as an argument

drupal cr menu
0

Drush cc still (or again?) works as it did in v7 you can do e.g.: drush cc css-js or drush cc render see the link you allready gave: https://drushcommands.com/drush-8x/cache/cache-clear/

if you simply do drush cc you will get a list of options. ('menu' is not one of them)

$ drush cc
Enter a number to choose which cache to clear.
 [0]  :  Cancel         
 [1]  :  drush          
 [2]  :  theme-registry 
 [3]  :  router         
 [4]  :  css-js         
 [5]  :  module-list    
 [6]  :  theme-list     
 [7]  :  render         
 [8]  :  token          
 [9]  :  views

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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