this is a follow-up to #2902603: Disable memcache on local or dev environments (Drupal 7) for Drupal 8.
In Drupal 7 the way to disable memcache for local and/or development environments was to just not include the path to the memcache.inc file in settings.php or settings.local.php
However, it seems there is no setting for Drupal 8 that enable/disables memcache from the settings.php (or at least I cannot find documentation of this).
For example, if memcache.so (or memcached.so) extensions are disabled on a local environment php configuration, and the memcache Drupal module is left enabled, you end up with an error when you access a page.
Drupal\memcache\MemcacheException: No Memcache extension found in
Drupal\memcache\Driver\MemcacheDriverFactory->initialize() (line 172 of modules/contrib/memcache/src/Driver/MemcacheDriverFactory.php).
I'm also seeing a different error:
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "memcache.factory". Did you mean one of these: "cache_factory", "image.factory"? in Drupal\Component\DependencyInjection\Container->get() (line 153 of core/lib/Drupal/Component/DependencyInjection/Container.php).
Drupal::service('memcache.factory') (Line: 68)
Drupal\memcache_admin\EventSubscriber\MemcacheAdminSubscriber->displayStatistics(Object, 'kernel.response', Object)
Is there a way to disable memcache from settings.local.php without having to disable the Drupal module?
Comments
Comment #2
jwilson3Even when I place all of the memcache settings inside an if statement in settings.php, this doesn't work:
Am I missing something?
Comment #3
jwilson3Comment #4
jwilson3A colleague, @marthinal, has determined that memcache module doesn't need to be enabled in the site (ie, in core.extensions.yml) so this may actually be one way to solve this problem, although not ideal.
Indeed Acquia has a statement that says the memcache module does not need to be enabled for the configuration to work:
I will test locally and report back.
Comment #5
jwilson3I've narrowed down the problem to being caused by show_memcache_statistics being set to 1 in memcache_admin.settings.yml
If I set show_memcache_statistics to 0 in settings.local.php and ensure $settings['memcache'] is not set by wrapping it in an if statement like the one in comment #2, the problems go away.
So, currently, to disable memcache definitively in local environments, without having to manually go and disable the modules in Drupal, add the following lines to your settings.local.php:
This is unfortunate and confusing and so maybe there is something that could be done in memcache_admin module to respect presence or absence of
$settings['memcache']before trying to load?Comment #6
jwilson3Comment #7
jedgar1mx commentedI'm having the same issue. However, since I'm enabling
memcache lockingit requires addingmemcacheto myservice.ymlso I have to comment it out every time. Wondering if there is an easier option. 🤔Comment #8
crystaldawn commentedIs there movement on this? It's impractical to have memcache on local envs. Nothing suggested here works (including comment #5, it doesnt do anything) to disable memcache in a local env while memcache is required in a prod env. Currently the only workaround I see that actually works is to install local memcache servers and thats not an acceptable solution.
This problem renders drush si unusable.
Comment #9
fgmIt is actually very practical to have memcache on local env, and will often improve your response time significantly over DB cache.
If you want to disable, just do not enable the module and do not add the settings.php lines enabling the cache, it's really no big deal.
And as to the problem with install, you shouldn't be using memcache (i.e. have it in settings) during install anyway.
Comment #10
crystaldawn commentedThanks for the reply but it's not useful at all as it doesnt fix the underlying problem.
Since when is it a good plan to have caching enabled in a local env that's destined for a front end developer and jr backend devs that wouldnt know something might be memcache related? That doesnt make any sense. It's for the same reason that css/js aggregation are disabled and no varnish servers exist yet those modules are still installed, but are simply disabled via settings.php files. Why should memcache be any different (although aggregation isnt a module, varnish very much is).
The bottom line is that the module does need to be installed, but it needs to be disabled via settings options. The fix is to simply change line 21 of the memcache.install file: $requirements['memcache_extension']['severity'] = REQUIREMENT_WARNING instead of REQUIREMENT_ERROR and add code that allows disabling of the functionality via settings.php file options. I didnt realize this would be that difficult to convey. Not every scenario is ripe for caching.