Blogs

Blogs

From our minds to yours

Disable Drupal 8 Caching During Development

How to disable page cache

We know Drupal 8 has 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:
    $settings['cache']['bins']['render'] = 'cache.backend.null';

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.

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

    Image
  2. Uncomment the $settings variable for that section:
    $settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
  3. Open settings.php file in sites/default directory and , locate the section that starts with "settings.local.php".Image
  4. Uncomment the section:

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

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

    }

  5. 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

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

     

    Image

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

    1 - drush cache-rebuild

    2 - drush cr

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

LEAVE A COMMENT

Fields marked with an * are mandatory.