public function cas($cas_token, $key, $value, $expiration = 0) {
    $key = $this->getPrefixKey($key);
    $request = new MemcacheSetRequest();
    $response = new MemcacheSetResponse();

    $memcache_flag = 0;
    $serialized_value = MemcacheUtils::serializeValue($value, $memcache_flag);

    $item = $request->addItem();
    $item->setKey($key);
    $item->setValue($serialized_value);
    $item->setFlags($memcache_flag);
    $item->setSetPolicy(SetPolicy::CAS);
    $item->setCasId($cas_token);
    $item->setExpirationTime($expiration);

    try {
      ApiProxy::makeSyncCall('memcache', 'Set', $request, $response);
    } catch (Error $e) {
      $this->result_code = self::RES_FAILURE;
      return false;
    }

    switch ($response->getSetStatusList()[0]) {
      case SetStatusCode::STORED:
        $this->result_code = self::RES_SUCCESS;
        return true;
      case SetStatusCode::NOT_STORED:
        $this->result_code = self::RES_NOTSTORED;
        return false;
      case SetStatusCode::EXISTS:
        $this->result_code = self::RES_DATA_EXISTS;
        return false;
      default:
        $this->result_code = self::RES_FAILURE;
        return false;
    }
  }
public function cas($cas_token, $key, $value, $expiration = 0) {
    $key = $this->getPrefixKey($key);
    $request = new MemcacheSetRequest();
    $response = new MemcacheSetResponse();

    $memcache_flag = 0;
    $serialized_value = MemcacheUtils::serializeValue($value, $memcache_flag);

    $item = $request->addItem();
    $item->setKey($key);
    $item->setValue($serialized_value);
    $item->setFlags($memcache_flag);
    $item->setSetPolicy(SetPolicy::CAS);
    $item->setCasId($cas_token);
    $item->setExpirationTime($expiration);

    try {
      ApiProxy::makeSyncCall('memcache', 'Set', $request, $response);
    } catch (Error $e) {
      $this->result_code = self::RES_FAILURE;
      return false;
    }

    switch ($response->getSetStatusList()[0]) {
      case SetStatusCode::STORED:
        $this->result_code = self::RES_SUCCESS;
        return true;
      case SetStatusCode::NOT_STORED:
        $this->result_code = self::RES_NOTSTORED;
        return false;
      case SetStatusCode::EXISTS:
        $this->result_code = self::RES_DATA_EXISTS;
        return false;
      default:
        $this->result_code = self::RES_FAILURE;
        return false;
    }
  }
public function cas ( $ cas_token , $ key , $ value , $ expiration = 0 ) { $ key = $ this -> getPrefixKey ( $ key ) ; $ request = new MemcacheSetRequest ( ) ; $ response = new MemcacheSetResponse ( ) ; $ memcache_flag = 0 ; $ serialized_value = MemcacheUtils :: serializeValue ( $ value , $ memcache_flag ) ; $ item = $ request -> addItem ( ) ; $ item -> setKey ( $ key ) ; $ item -> setValue ( $ serialized_value ) ; $ item -> setFlags ( $ memcache_flag ) ; $ item -> setSetPolicy ( SetPolicy :: CAS ) ; $ item -> setCasId ( $ cas_token ) ; $ item -> setExpirationTime ( $ expiration ) ; try { ApiProxy :: makeSyncCall ( 'memcache' , 'Set' , $ request , $ response ) ; } catch ( Error $ e ) { $ this -> result_code = self :: RES_FAILURE ; return false ; } switch ( $ response -> getSetStatusList ( ) [ 0 ] ) { case SetStatusCode :: STORED : $ this -> result_code = self :: RES_SUCCESS ; return true ; case SetStatusCode :: NOT_STORED : $ this -> result_code = self :: RES_NOTSTORED ; return false ; case SetStatusCode :: EXISTS : $ this -> result_code = self :: RES_DATA_EXISTS ; return false ; default : $ this -> result_code = self :: RES_FAILURE ; return false ; } }
Performs a set and check operation, so that the item will be stored only
if no other client has updated it since it was last fetched by this
client.

@param mixed $cas_token Unique memcached assigned value.
@param string $key The key under which to store the value.
@param mixed $value The value to store.
@param int $expiration The expiration time, defaults to 0.

@return bool True on success, or false on failure.
Performs a set and check operation so that the item will be stored only if no other client has updated it since it was last fetched by this client .