Hoppa till huvudinnehåll
Menu

Den här sidan använder cookies. Om du fortsätter använda sidan så accepterar du användandet av cookies. Läs mer om cookies

Jag förstår

Handle non-activated services on site install

In our developer workflow we install the site continuously during development, as a health check of the code base. One of the problems we have in this workflow is when we declare a service that belongs to a module that is not activated yet during the install, like Memcache module.

In our developer workflow we install the site continuously during development, as a health check of the code base. One of the problems we have in this workflow is when we declare a service that belongs to a module that is not activated yet during the install, like Memcache module.
This is what a site needs normally in settings.php

$settings['memcache']['servers'] = ['localhost:11211' => 'default']; 
$settings['memcache']['bins'] = ['default' => 'default']; 
$settings['memcache']['key_prefix'] = 'foo_bar'; 
$settings['cache']['default'] = 'cache.backend.memcache';

This works perfect to add on a runnings site when the module is activated and the service cache.backend.memcache is available.

But when drupal loads the file during the install – which happens during bootstrap, it does that before the module is activated, so we get an error: 'You have requested a non-existent [error] service "cache.backend.memcache" Error'.

A good solution for this should be to use the function drupal_installation_attempted that returns TRUE if we are installing the site, even during the bootstrap, so we do like this:

if (!drupal_installation_attempted()) {
  $settings['cache']['default'] = 'cache.backend.memcache';
} 

When site is installed and drupal loads settings.php, the memcache cache service is available.

This would off course also work for other services that you declare in settings.php.

Happy caching!

Photo by Matthias Buehler License: GPL 2.0

 

Vi hjälper dig nå resultat. Kontakta oss Ring direkt på 08-20 90 04.

Cache in Drupal 8: How it worked, and what we wanted to be solved in D8

If you just want your content to be cached before Drupal 8, there were almost no problems, just turn on caching for anonymou…
MDN

Cache in Drupal 8: Introduction

In a series of blog posts we will go through how caching works in Drupal 8, to try to demystify the caching layer in Drupal …
MDN

Updating taxonomy term name in Drupal 8

Here you can read how to use hook update for updating taxonomy terms in Drupal 8.