Last updated February 20, 2017. Created on October 22, 2015.
Edited by Karol Haltenberger, Luis Celadita, jordimateubesancon, stevepurkiss. Log in to edit this page.

Don't add comments to this page. Edit it instead

When you are developing a module or theme you have to clear Drupal's cache (render cache, dynamic page cache, Twig cache) very often to see the changes being applied. You can disable caching for development.

So if your terminal looks like this:

boris-laptop:www boris$ drush cr
Cache rebuild complete.                      [ok]
boris-laptop:www boris$ drush cr
Cache rebuild complete.                      [ok]
boris-laptop:www boris$ drush cr
Cache rebuild complete.                      [ok]
boris-laptop:www boris$ drush cr
Cache rebuild complete.                      [ok]
boris-laptop:www boris$ drush cr
Cache rebuild complete.                      [ok]
Et cetera

then try the following:

Don't add comments to this page. Edit it instead

Enable local development settings

1. Copy and rename the sites/example.settings.local.php to sites/default/settings.local.php:

$ cp sites/example.settings.local.php sites/default/settings.local.php

2. Open settings.php file in sites/default and uncomment these lines:

if (file_exists(__DIR__ . '/settings.local.php')) {
   include __DIR__ . '/settings.local.php';
 }

This will include the local settings file as part of Drupal's settings file.

3. Open settings.local.php and uncomment (or add) this line to enable the null cache service:

$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml';

By default development.services.yml contains the settings to disable Drupal caching:

services:
  cache.backend.null:
    class: Drupal\Core\Cache\NullBackendFactory

NOTE: Do not create development.services.yml, it exists under /sites

4. In settings.local.php change the following to be TRUE if you want to work with enabled css- and js-aggregation:

$config['system.performance']['css']['preprocess'] = FALSE;
$config['system.performance']['js']['preprocess'] = FALSE;

5. Uncomment these lines in settings.local.php to disable the render cache and disable dynamic page cache:

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

If you do not want to install test modules and themes, set the following to FALSE:

$settings['extension_discovery_scan_tests'] = TRUE;

6. Open development.services.yml in the sites folder and add the following block to disable the twig cache:

parameters:
  twig.config:
    debug: true
    auto_reload: true
    cache: false

NOTE: If the parameter block is already present in the yml file, append the twig.config block to it.

7. Afterwards you have to rebuild the Drupal cache otherwise your website will encounter an unexpected error on page reload. This can be done by with drush:

drush cr

or by visiting the following URL from your Drupal 8 website:

http://yoursite/core/rebuild.php

Now you should be able to develop in Drupal 8 without manual cache rebuilds on a regular basis.

Your final development.services.yml should look as follows (mind the indentation):

# Local development services.
#
# To activate this feature, follow the instructions at the top of the
# 'example.settings.local.php' file, which sits next to this file.
parameters:
  http.response.debug_cacheability_headers: true
  twig.config:
    debug: true
    auto_reload: true
    cache: false
services:
  cache.backend.null:
    class: Drupal\Core\Cache\NullBackendFactory

Don't add comments to this page. Edit it instead

Use Drupal Console development mode

You can use Drupal Console to switch site into development mode:

Use site:mode command like this:

drupal site:mode dev

The command will override site's services.yml file and console output will show you which parameters has been changed.

According to this post this command has been temporarily removed and you will receive Command "site:mode", is not a valid command name.

Don't add comments to this page. Edit it instead

Find cache bins

To find all available (but not necessarily enabled) cache bins:

find . -type f -name *.services.yml | \
xargs sed -E -n  's/.*cache\.(.*):.*/\1/p' | \
grep -v "backend\|html.twig" | \
sort -u | \
awk -vORS=\',\' '{ print $1 }' | \
sed "s/,'$//" | sed "s/^/'/"

Note that in OSX you might need to install and run 'gawk' instead of 'awk' in order for the above command to work. You can use brew to install gawk:

brew install gawk

Then you could copy/paste it in your settings.php file and disable caching like this:

$cache_bins = array('bootstrap','config','data','default','discovery','dynamic_page_cache','entity','menu','migrate','render','rest','static','toolbar');
foreach ($cache_bins as $bin) {
  $settings['cache']['bins'][$bin] = 'cache.backend.null';
}

Disable cached response headers

If HTTP headers include cached Response Headers: Expires and Request Headers: Cache-Control then it is probably good to disable them during development:

On MAMP 4+ uncheck Apache settings cache_module. You might have to disable disk_cache_module and mem_cache_module as well if you are having problems restarting your apache. Close and re-open MAMP 4+.

Don't add comments to this page. Edit it instead

Disable caching in your browser

Although Drupal is not caching, your browser does. That can be confusing when you have disabled all caching in the settings files and your CSS changes are not visible after a webpage reload. For example, in Google Chrome you can disable caching while the dev tools are opened:

Disable caching in Google Chrome

Disable caching in Google Chrome

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.