getValueAndCas example

public function putOffExpiration(Key $key, float $ttl)
    {
        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();
        }

        
Home | Imprint | This part of the site doesn't use cookies.