5

It takes more time to clear caches and it also needs to be done more frequently for the each CSS or functionality wise changes.

Are there any alternatives available?

7

Disable Drupal 8 caching during development

When you are developing a module or a 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.

Steps

  1. Copy and rename the file sites/example.settings.local.php to sites/default/settings.local.php:
$ cp sites/example.settings.local.php sites/default/settings.local.php
  1. Uncomment these lines in sites/default/settings.php:
if (file_exists(__DIR__ . '/settings.local.php')) {
    include __DIR__ . '/settings.local.php';
}
  1. If you want to keep CSS and JS aggregation and preprocessing, change these lines in sites/default/settings.local.php to TRUE:
$config['system.performance']['css']['preprocess'] = TRUE;
$config['system.performance']['js']['preprocess'] = TRUE;
  1. Uncomment these line in sites/default/settings.local.php:
$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = cache.backend.null';
  1. Add the following lines to sites/development.services.yml:
parameters:
  twig.config:
    debug: true
    auto_reload: true
    cache: false

(source: drupal.org)

| improve this answer | |
  • This doesn't work. Changing $config['system.performance']['css']['preprocess'] to FALSE does not disable CSS aggregation. Additional steps must be needed to disable CSS aggregation besides those supplied here. – arnoldbird Feb 5 '19 at 16:32
5

The easier way to "Disable Drupal 8 caching during development" is using DrupalConsole.

drupal site:mode dev

Source - Debugging compiled Twig templates

| improve this answer | |
2

Depend on your working area.

Steps 01)

a) You can disable cache from /admin/config/development/performance

b) You can copy a file from sites/example.settings.local.php to sites/default/example.settings.local.php then replace by settings.local.php. For this file you have comment out the following codes from settings.php.

/**
 * Load local development override configuration, if available.
 *
 * Use settings.local.php to override variables on secondary (staging,
 * development, etc) installations of this site. Typically used to disable
 * caching, JavaScript/CSS compression, re-routing of outgoing emails, and
 * other things that should not happen on development and testing sites.
 *
 * Keep this code block at the end of this file to take full effect.
 */
if (file_exists(__DIR__ . '/settings.local.php')) {
  include __DIR__ . '/settings.local.php';
}

Then you have to comment out the following section from /sites/default/settings.local.php

/**
 * Disable the render cache (this includes the page cache).
 *
 * Note: you should test with the render cache enabled, to ensure the correct
 * cacheability metadata is present. However, in the early stages of
 * development, you may want to disable it.
 *
 * This setting disables the render cache by using the Null cache back-end
 * defined by the development.services.yml file above.
 *
 * Do not use this setting until after the site is installed.
 */
$settings['cache']['bins']['render'] = 'cache.backend.null';

If you may get an error. Do not worry. Just enter in your browser address bar your_site_domain.com/rebuild.php.

Steps 02)

Specially for Drupal 8 there is a nice tools is called Drupal Console. Installation and documentation is great. You can see using the site http://www.drupalconsole.com/.

When you will finish the installation, I hope you will be more happy for the command line features. Like you can clear cache using the following command-

$ drupal cache:rebuild

OR

$ drupal cr all
| improve this answer | |
1

Source Disable Drupal 8 caching during development

Steps

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

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

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

  1. Open settings.local.php and uncomment this line to enable the null cache service:

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

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

  1. 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;

  1. 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 following to FALSE

$settings['extension_discovery_scan_tests'] = TRUE;

  1. Open development.services.yml in the sites folder and add the following block (to disable twig cache)

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

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

  1. Finished! Now you're able to develop in Drupal 8 without manual cache rebuilds on a regular basis.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.