blog-banner

Disable Drupal 8 Cache During Development

  • Cache
  • Drupal 8
  • Drupal Planet

Drupal 8 Disable Cache 

We know Drupal 8 has a heavy caching mechanism, so we need to clear the cache for changes made in the twig file or some other file to reflect in the site. Basically, a theme or developer won't love the caching system in the development stage. So it is better to disable the cache in the development stage rather than clearing the cache for every change being made.

And here are the steps to disable cache and save your valuable time:

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

cp sites/example.settings.local.php sites/default/settings.local.php
  • Open a settings.php file in the sites/default directory and uncomment these lines:

if (file_exists(__DIR__ . '/settings.local.php')) {
  include __DIR__ . '/settings.local.php';
}
  • Uncomment the following lines in settings.local.php to disable the render cache and dynamic page cache

$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
  • Finally, 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
  • After the above steps, you need to rebuild the Drupal cache. Otherwise, your website will encounter an unexpected error on page reload. This can be done by running the following Drush comment:

drush cache-rebuild (or) drush cr
  • Finished! Now you will be able to develop in Drupal 8 without manual cache rebuilds on a regular basis.

  • Detailed documentation in Drupal 8 is available on Drupal.org.

Get awesome tech content in your inbox