Exemplo n.º 1
0
 /**
  * Caches value by key
  *
  * @param string $key
  * @param mixed $value
  * @param int $expireIn Seconds
  * @return bool
  */
 public function set($key, $value, $expireIn = 0)
 {
     try {
         return (bool) $this->cache->upsert($this->prepareKey($key), $this->serializeCompound($value), array('expiry' => $expireIn));
     } catch (\CouchbaseException $e) {
         return false;
     }
 }
Exemplo n.º 2
0
 private function existsAndUpsert($key, $value, $expire = 0)
 {
     if ($this->existsInternal($key)) {
         return false;
     }
     $this->storage->upsert($key, $value, ['expiry' => $expire]);
     return true;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function flush()
 {
     // depending on config & client version, flush may not be available
     try {
         /*
          * Flush wasn't always properly implemented[1] in the client, plus
          * it depends on server config[2] to be enabled. Return status has
          * been null in both success & failure cases.
          * Flush is a very pervasive function that's likely not called
          * lightly. Since it's probably more important to know whether or
          * not it succeeded, than having it execute as fast as possible, I'm
          * going to add some calls and test if flush succeeded.
          *
          * 1: https://forums.couchbase.com/t/php-flush-isnt-doing-anything/1886/8
          * 2: http://docs.couchbase.com/admin/admin/CLI/CBcli/cbcli-bucket-flush.html
          */
         $this->client->upsert('cb-flush-tester', '');
         $manager = $this->client->manager();
         if (method_exists($manager, 'flush')) {
             // ext-couchbase >= 2.0.6
             $manager->flush();
         } elseif (method_exists($this->client, 'flush')) {
             // ext-couchbase < 2.0.6
             $this->client->flush();
         } else {
             return false;
         }
     } catch (\CouchbaseException $e) {
         return false;
     }
     try {
         // cleanup in case flush didn't go through; but if it did, we won't
         // be able to remove it and know flush succeeded
         $result = $this->client->remove('cb-flush-tester');
         return (bool) $result->error;
     } catch (\CouchbaseException $e) {
         // exception: "The key does not exist on the server"
         return true;
     }
 }
Exemplo n.º 4
0
 protected function doSet($key, $var, $expiry = 0)
 {
     $meta = $this->bucket->upsert($key, $var, array('expiry' => $expiry));
     return is_null($meta->error);
 }
Exemplo n.º 5
0
 protected function doSet($key, $var, $expiry = 0)
 {
     if ($this->debug) {
         KalturaLog::debug("Bucket name [{$this->name}] key [{$key}] var [" . print_r($var, true) . "]");
     }
     $meta = $this->bucket->upsert($key, $var, array('expiry' => $expiry));
     return is_null($meta->error);
 }