/** * Returns cached $callback result * * @param callable $callback * @param array $args Callback arguments * @param int $expireIn Seconds * @param string|null $cacheKeySuffix Is needed to avoid collisions when callback is an anonymous function * @return mixed * @throws \InvalidArgumentException */ public function getCached($callback, array $args = array(), $expireIn = 0, $cacheKeySuffix = null) { if (!is_callable($callback)) { throw new \InvalidArgumentException('First argument of getCached method has to be a valid callback'); } $key = $this->getCallbackCacheKey($callback, $args, $cacheKeySuffix); try { $result = $this->cache->get($key)->value; } catch (\CouchbaseException $e) { $result = call_user_func_array($callback, $args); $this->cache->insert($key, $this->serializeCompound($result), array('expiry' => $expireIn)); } return $this->unserializeCompound($result); }
/** * {@inheritdoc} */ public function add($key, $value, $expire = 0) { try { $result = $this->client->insert($key, $value, array('expiry' => $expire)); } catch (\CouchbaseException $e) { return false; } return !$result->error; }
protected function setInternal($key, $value, $expire, $upsert = false) { if ($upsert) { $this->storage->upsert($key, $value, ['expiry' => $expire]); } else { $this->storage->insert($key, $value, ['expiry' => $expire]); } return true; }
protected function doAdd($key, $var, $expiry = 0) { KalturaLog::debug("key [{$key}], var [" . print_r($var, true) . "]"); try { $meta = $this->bucket->insert($key, $var, array('expiry' => $expiry)); } catch (CouchbaseException $e) { if ($e->getCode() == self::ERROR_CODE_THE_KEY_ALREADY_EXISTS_IN_THE_SERVER) { return false; } throw $e; } return is_null($meta->error); }