Disable caching Drupal 8 in development process

Submitted by phannphong on Sun, 03/24/2019 - 00:42
Disable caching in development process

If you have been read Some basic drush commands, you can use Drush by running drush cr command line. However, this way is not useful when you're in the development process because you need to run the command line every time you change the code.

I'll guide you follow 2 ways:

1. MANUAL CONFIGURATION

1.1. Copy example.settings.local.php in sites/ folder to settings.local.php and put it in sites/default/ path.

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

1.2. Uncomment this code (add it if you don't see) in settings.php:

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

1.3. Check settings.local.php remove the comment of below code:

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

Uncomment above code if the code put in the comment (remove #).

Default in  development.service.yml has the code to disable Drupal cache:

parameters:
  http.response.debug_cacheability_headers: true
services:
  cache.backend.null:
    class: Drupal\Core\Cache\NullBackendFactory

1.4. To enable css and js aggregation, please set TRUE for css and js parameters in the settings.local.php:

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

1.5. To disable cache render, uncomment below code in the settings.local.php:

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

1.6. To disable dynamic page cache, uncomment below code in the settings.local.php:

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

1.7. To disable internal page cache, in the settings.local.php, uncomment this below code:

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

1.8. If you're working with development module or theme, you'll uncomment the below code and set the value to FALSE in the settings.local.php

$settings['extension_discovery_scan_tests'] = FALSE;

1.9. To disable cache twig, add the below codes in the development.services.yml (in the sites folder):

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

Finally, the development.services.yml will look like this:

# 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

1.10. Run cache rebuild to sure anything is update:

drush cr

2. DRUPAL CONSOLE

Just run this command line:

drupal site:mode dev

Back to enable caching:

drupal site:mode prod

Reference: https://www.drupal.org/node/2598914