7

In drupal9 my drupal8 local.settings.php conf generate an error when i empty cache

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have [error] requested a non-existent service "cache.backend.null". Did you mean one of these: "cache.backend.apcu", "cache.backend.memory", "cache.backend.php"? in /data-platforms/platforms/drupal9-dev/core/lib/Drupal/Component/DependencyInjection/Container.php:156

this has to do with

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

what do i have to change here for drupal9 ?

1
  • 2
    It’s the same as for D8 - you need to be including your development.services.yml in the container ymls in settings.php and then rebuild cache
    – Clive
    Jun 29, 2021 at 14:25

1 Answer 1

12

As Clive mentioned, this is the same for D8 and D9 and cache.backend.null is defined in development.services.yml so the easiest way to use it is to add development.services.yml to your container ymls.

To do this add the following near the top of your settings file (code taken from core's default example.settings.local.php) :

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

Additionally, example.settings.local.php tells you that you must do this to use cache.backend.null:

/**
 * Disable the render 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.
 *
 * Only use this setting once the site has been installed.
 */
# $settings['cache']['bins']['render'] = 'cache.backend.null';

If, for some reason, you don't want to use the default development.services.yml file, you could instead use a custom.services.yml file as long as it includes the cache.backend.null definition.

To do this, you'd need to add the following to your settings file:

/**
 * Enable custom services.
 */
$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/custom.services.yml';

And then in your sites/custom.services.yml file:

services:
  cache.backend.null:
    class: Drupal\Core\Cache\NullBackendFactory
1
  • Did the trick for me. I added development.services.yml to container_yamls in sites/default/settings.local.php on ddev with Platform.sh integration.
    – Jono
    Oct 6, 2023 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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