Enable or disable Drupal 8 cache from the settings.php file

Enable or disable Drupal 8 cache from the settings.php file

Disabling the cache on a local Drupal 8 website is handy when developing. But on your live website you want the caching to stay enabled at all times.

Syncing configuration in Drupal 8 is great but you don't want to overwrite your cache settings on your live website. A solution is to force caching on your live environment by adding the following in your settings.php file:

$config['system.performance']['css']['preprocess'] = 1;
$config['system.performance']['css']['gzip'] = 1;
$config['system.performance']['js']['preprocess'] = 1;
$config['system.performance']['js']['gzip'] = 1;
$config['system.performance']['cache']['page']['max_age'] = 86400;

If you want to change more stuff between environments I recommend to take a look at the Config split contrib module.

Tags