Note: This page has been moved to https://www.drupal.org/docs/develop/development-tools/disable-caching.

Disabling Drupal 8, Drupal 9 and Drupal 10 caching (render cache, dynamic page cache, Twig cache) during development is useful for seeing changes without clearing the cache.

IMPORTANT NOTE: Accessing the site as an anonymous user still makes use of caching even when local development settings have been enabled. You must be logged in to view your site with caches disabled.

Load local development settings

Include the local settings file as part of Drupal's settings file.

Copy sites/example.settings.local.php to sites/default/settings.local.php:

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

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

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

Configure development.services.yml

The development.services.yml file is located under /sites.

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

Twig cache: We added a twig.config section in the development.services.yml disabling the cache.

Open settings.local.php and make sure development.services.yml is enabled.

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

Beware of scaffolding

Depending on your composer.json, development.services.yml may be overwritten during scaffolding. To prevent certain scaffold files from being overwritten every time you run a Composer command you need to specify them one by one in the "extra" section of your project's composer.json. See the docs on Excluding scaffold files.

The following snippet prevents the development.services.yml from being regularly overwritten:

"drupal-scaffold": {
    "locations": {
        "web-root": "web/"
    },
    "file-mapping": {
        "[web-root]/sites/development.services.yml": false
    }
},

Configure settings.local.php

Change the following to TRUE if you want to work with enabled css- and js-aggregation:

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

Uncomment these lines to disable the Render Cache, disable the Internal Page Cache and disable Dynamic Page Cache:

$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['page'] = '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'] = FALSE;

Rebuild cache

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-10 website:

http://yoursite/core/rebuild.php

Use Mix module

If above approach seems hard for you or you just want a simpler way to disable caches, you can install the Mix module, and switch between Dev/Prod modules by simply toggling the "Enable development mode" checkbox, no manual works on settings.php and *services.yml files.

Following screenshot shows the differences between Dev mode and Prod mode when use Mix module.
Mix Development mode

Use Drupal Console development mode

You can use Drupal Console to switch site into development mode and back to production mode with the site:mode command

NOTE: You'll need Drupal Console 1.9.5 or higher to support Drupal 9 (with PHP 7), and currently not support PHP 8 and Drupal 10.

Because Drupal Console is not disabling all the possible caches automatically for you. So manual edits in your configuration might still be needed.

Example:

drupal site:mode dev

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';
}

Alternative: develop with caching enabled

Disabling caching has some drawbacks. The whole site responds slower, and rebuilding all caches takes a while too. Doing this a lot, and all those seconds waiting for a response add up. For an approach to developing with the cache enabled, see Drupal 8 development with caching on.

Sendfile Settings

Sometimes local installed environments will have Sendfile enable in their server configuration. Sendfile is used by the server to cache static files, and can greatly improve performance on production environments. However, during development, this can cause CSS and Javascript files to be served from the cache, rather than a fresh copy. You can set Sendfile to off, depending on the environment's web server (Apache or Nginx).

Apache requires an update in the httpd.conf (or sometimes apache.conf)
EnableSendfile off
Nginx requires an update in the nginx.conf
sendfile off

PHP OpCode Caches

Sometimes your latest changes within your PHP files might not be reflected on your webpage due to caches via PHP extensions. One popular PHP code cache is the PHP OpCode extension. Drupal recommends you to enable the PHP OpCode extension for faster code execution. However, it can be sometimes confusing when you want to see the latest changes in your PHP code reflected in your webbrowser or any command line script (e.g. Drush command). So if you are unsure about your code execution during your development process, disabling or configuring the PHP OpCode extension might be a solution. Be aware that the PHP OpCode extension isn't mostly the reason for caches in your development process. Read more about PHP OpCode caches in the following blog article: PHP Performance I: Everything You Need to Know About OpCode Caches.

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