Rebuilding cache in Console or Drush

Drupal utilizes caching to store plugin definitions, routes, and so on. When you add a new plugin definition or new route, you need to rebuild Drupal's cache for it to be recognized.

In this recipe, we will walk you through using both Drush and Console to clear various cache bins in Drupal. It is important to know how to clear specific cache bins so that you do not need to rebuild everything, if possible.

How to do it…

  1. Open a terminal and navigate to an installed Drupal directory.
  2. We use the cache-rebuild command in Drush to rebuild all of Drupal's caches, including routes:
    $ drush cache-rebuild
    Cache rebuild complete. 
    
  3. Drush will bootstrap Drupal to a full site and invoke a full cache clear.
  4. In Console, we use the cache:rebuild command to clear specific cache bins:
    $ drupal cache:rebuild
     Select cache. [all]:
     > all
     Rebuilding cache(s), wait a moment please.
     [OK] Done clearing cache(s).  
    
  5. If you select all, the same operation is run in Drush. However, Console is set up to allow distinct cache bins in future development.
  6. If you only need to rebuild your routes in Drupal, you can use the router:rebuild command in Console:
    $ drupal router:rebuild
    Rebuilding routes, wait a moment please 
     [OK] Done rebuilding route(s). 
    
  7. Instead of clearing all caches to rebuild routes, it can be done directly with this command.
  8. Drush provides twig-compile to rebuild template changes without clearing all caches:
    $ drush twig-compile
    

How it works…

Both Drush and Console will load files off your Drupal site and bootstrap the application. This allows the commands to invoke functions and methods found in Drupal.

Currently, Drush does not implement the dependency injection container, and still needs to rely on procedural functions in Drupal. Console, however, harnesses the dependency injection container, allowing it to reuse Drupal's container and services.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset