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.
cache-rebuild
command in Drush to rebuild all of Drupal's caches, including routes:$ drush cache-rebuild Cache rebuild complete.
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).
all
, the same operation is run in Drush. However, Console is set up to allow distinct cache bins in future development.router:rebuild
command in Console:$ drupal router:rebuild Rebuilding routes, wait a moment please [OK] Done rebuilding route(s).
twig-compile
to rebuild template changes without clearing all caches:$ drush twig-compile
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.