Disable caching Drupal 8 in development process

Submitted by phannphong on 24 March, 2019
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. Remove comment sign before following these 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 sign of below code:

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

Remove comment sign (#) if the code has it.

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 disable css and js aggregation, please set FALSE for css and js parameters in the settings.local.php:

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

1.5. To disable cache of rendering, remove comment sign of the following code in the settings.local.php:

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

1.6. To disable cache of dynamic page, remove comment sign of the following code in the settings.local.php:

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

1.7. To disable cache of internal page, in the settings.local.php, remove comment sign of the following code:

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

1.8. If you're working with development module or theme, you'll want to remove comment sign of the following code and set the value to FALSE in the settings.local.php

$settings['extension_discovery_scan_tests'] = FALSE;

1.9. To disable cache of 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 applied.

drush cr

2. DRUPAL CONSOLE

If your project has drupal console (how to install it). You just need to run this command line:

drupal site:mode dev

Back to disable caching:

drupal site:mode prod

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

Comments

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. Remove comment sign before following these 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 sign of below code:

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

Remove comment sign (#) if the code has it.

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 disable css and js aggregation, please set FALSE for css and js parameters in the settings.local.php:

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

1.5. To disable cache of rendering, remove comment sign of the following code in the settings.local.php:

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

1.6. To disable cache of dynamic page, remove comment sign of the following code in the settings.local.php:

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

1.7. To disable cache of internal page, in the settings.local.php, remove comment sign of the following code:

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

1.8. If you're working with development module or theme, you'll want to remove comment sign of the following code and set the value to FALSE in the settings.local.php

$settings['extension_discovery_scan_tests'] = FALSE;

1.9. To disable cache of 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 applied.

drush cr

2. DRUPAL CONSOLE

If your project has drupal console (how to install it). You just need to run this command line:

drupal site:mode dev

Back to disable caching:

drupal site:mode prod

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

Comments