The Readme file states that "Locks have not yet been implemented using the memcache module.".

The Readme file also says about "Stampede Protection": "To avoid lock stampedes, it is important that you enable the memcache lock implementation when enabling stampede protection..."

But the lock implemetation seems to work file - I added this to my services.yml to enable the feature:

services:
  # Replaces the default lock backend with a memcache implementation.
  lock:
    class: Drupal\Core\Lock\LockBackendInterface
    factory: ['@memcache.lock.factory', get]

  # Replaces the default persistent lock backend with a memcache implementation.
  lock.persistent:
    class: Drupal\Core\Lock\LockBackendInterface
    factory: ['@memcache.lock.factory', get]
    arguments: [true]

If someone who knows more about this than myself can confirm that the locking backend fully works it should be added to the documentation.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vurt created an issue. See original summary.

j.b’s picture

Hi vurt,

How did you manage to get it working ?

You created a custom module and a corresponding services.yml ?

Then did you add something in the settings.php ?

I urgently need the locking system to be managed by memcached.
I have a live website with quite huge traffic and we are noticing frequent deadlocks related to the cache.

vurt’s picture

I just added the configuration to sites/default/services.yml, just like I wrote.

Have you enabled and configured the memcache module? Then you should not see database deadlocks on the cache tables. The (optional) memcache locking implementation only helps against deadlocks on the semaphore table.

j.b’s picture

Thanks,
It works.

bkosborne’s picture

This works but the code snippet needs to be updated. Looks like it was copied from the Redis module's implementation.

services:
  lock:
    class: Drupal\Core\Lock\LockBackendInterface
    factory: ['@memcache.lock.factory', get]
  lock.persistent:
    class: Drupal\Core\Lock\LockBackendInterface
    factory: ['@memcache.lock.factory', getPersistent]
vurt’s picture

Thank you very much for the correction! Yes this was from a Redis example because I could not find anything about Memcache and locking for Drupal 8.

And thank you very much for confirming that it works.

I double-checked if this is working by putting some debug output in the aquire() and release() functions. It really works.

kalpaitch’s picture

If the lock is present let's support it.

kalpaitch’s picture

Status: Active » Needs review

  • damiankloip committed 5b6a8da on 8.x-2.x
    Issue #2852460 by kalpaitch, bkosborne, vurt, damiankloip: Document...
damiankloip’s picture

Status: Needs review » Fixed
+++ b/README.txt
@@ -158,7 +158,19 @@ the default in this case but could be set using:
+      factory: ['@memcache.lock.factory', get]
+      arguments: [true]

This is not correct for memcache, the method is getPersistent. So #5 is correct. See attached interdiff. Committed and pushed with this. Thanks!

damiankloip’s picture

FileSize
722 bytes

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

vorapoap’s picture

I think the document should update to include the services.yml file in this way to avoid the .... The service "lock" has a dependency on a non-existent service "memcache.lock.factory". ..... issue.

https://docs.acquia.com/acquia-cloud/performance/memcached/locks/