Disable Drupal 8 caching during development

Image
Image

We know Drupal 8 has a many levels of caching Render caching, Dynamic page caching, Twig template caching, When you are developing a module or a theme it is better to disable cache on the development stage rather than clearing cache for every change being made .

 

  1. Copy and rename the sites/example.settings.local.php file as sites/default/settings.local.php.

     

    image

  2. In your settings.local.php file, locate the section that starts with "Disable the render cache".

     

    Image

  3. Uncomment the $settings variable for that section:

  4. $settings['cache']['bins']['render'] = 'cache.backend.null';

  5. Dynamic page caching: Dynamic page caching is when Drupal takes the entire rendered output of a page and stores it in the database (or another cache store; defaults to the database). Pages will only be cached for anonymous traffic and for users that don't have session data, like items in a shopping cart.

  6. In your settings.local.php file, locate the section that starts with "Disable Dynamic Page Cache".

     

    Image
  7. Uncomment the $settings variable for that section:

    $settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';

  8. Open settings.php file in sites/default directory and , locate the section that starts with "settings.local.php".

     

    Image

  9. Uncomment the section:

     

    if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) {

     include $app_root . '/' . $site_path . '/settings.local.php';

    }

  10. open development.services.yml in the sites folder and add the following lines (to disable twig cache)
     

    parameters:

     twig.config:

       debug: true

       auto_reload: true

       cache: false

  11. Your final development.services.yml should look as follows:

     

    Image

  12. After the above steps, you need to rebuild the Drupal cache.
     

    1 - drush cache-rebuild

    2 - drush cr

  13. Now After changes done, Drupal's caching system is effectively turned off.

Back