Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. MemcachedStore.php

function MemcachedStore::putOffExpiration

Overrides PersistingStoreInterface::putOffExpiration

1 call to MemcachedStore::putOffExpiration()
MemcachedStore::save in vendor/symfony/lock/Store/MemcachedStore.php
Stores the resource if it's not locked by someone else.

File

vendor/symfony/lock/Store/MemcachedStore.php, line 64

Class

MemcachedStore
MemcachedStore is a PersistingStoreInterface implementation using Memcached as store engine.

Namespace

Symfony\Component\Lock\Store

Code

public function putOffExpiration(Key $key, float $ttl) : void {
    if ($ttl < 1) {
        throw new InvalidTtlException(\sprintf('"%s()" expects a TTL greater or equals to 1 second. Got %s.', __METHOD__, $ttl));
    }
    // Interface defines a float value but Store required an integer.
    $ttl = (int) ceil($ttl);
    $token = $this->getUniqueToken($key);
    [
        $value,
        $cas,
    ] = $this->getValueAndCas($key);
    $key->reduceLifetime($ttl);
    // Could happens when we ask a putOff after a timeout but in luck nobody steal the lock
    if (\Memcached::RES_NOTFOUND === $this->memcached
        ->getResultCode()) {
        if ($this->memcached
            ->add((string) $key, $token, $ttl)) {
            return;
        }
        // no luck, with concurrency, someone else acquire the lock
        throw new LockConflictedException();
    }
    // Someone else steal the lock
    if ($value !== $token) {
        throw new LockConflictedException();
    }
    if (!$this->memcached
        ->cas($cas, (string) $key, $token, $ttl)) {
        throw new LockConflictedException();
    }
    $this->checkNotExpired($key);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal