Disable Drupal 8 caching during development

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

Comments

  1. Good job! Fruitful article. I like this very much. It is very useful for my research. It shows your interest in this topic very well. I hope you will post some more information about the software. Please keep sharing!!
    Drupal training in chennai |
    Drupal software

    ReplyDelete
  2. Nice post. Thank for sharing such a great information about disable Drupal 8 caching during development. Its very useful for me.

    ReplyDelete
  3. This is such a nice post which you shared here. it really helps me out. Keep sharing posts like these.

    Hire Drupal Developers |

    Drupal Development Company

    ReplyDelete
  4. Thank You for sharing this informative post. Looking forward to read more.
    Best Professional Web Development Services

    ReplyDelete
  5. Thanks for sharing this informative article on Disabling Drupal 8 caching during development with useful example. If you have any requirement to Hire Drupal Developers to develop an ecommerce web solution for your business please contact us and hire ecommerce developers from our team.

    ReplyDelete

Post a Comment

Popular posts from this blog

Install PHP 7.x on Linux Mint 18

Install Redis on ubuntu 14.04, 14.10, 15.04, 16.04 etc