/** * @inheritdoc */ public function get($key, $useCas = false) { $Result = $useCas ? $this->getConnection()->get($key, null, $this->casToken) : $this->getConnection()->get($key); if ($this->getConnection()->getResultCode() == Memcached::RES_SUCCESS) { $Item = new Item($key); $Item->unserialize($Result); return $Item; } else { return new Item($key); } }
/** * @inheritdoc */ public function get($key, $useCas = false) { if ($useCas) { $this->watched = (bool) $this->getClient()->watch($key); } $result = $this->getClient()->get($key); if (!is_null($result)) { $Item = new Item($key); $Item->unserialize($result); return $Item; } else { return new Item($key); } }
/** * @inheritdoc * @throws ConnectException when redis instance unavailable */ public function get($key, $useCas = false) { if ($useCas) { $this->watched = $this->getConnection()->watch($key); } try { $result = $this->getConnection()->get($key); if ($result !== false) { $Item = new Item($key); $Item->unserialize($result); return $Item; } else { return new Item($key); } } catch (KeyNotFoundException $Ex) { return new Item($key); } }
/** * Caching setter * @param string $field caching field name * @param mixed $Value caching value * @param int $type value type * @param int $expiration expiration timestamp * @param int $tries set tries count */ public function set($field, $Value, $type = Item::TYPE_STRING, $expiration = 0, $tries = self::TRIES_SET) { if ($tries > 0) { $this->load(true, true); $Item = new Item($field, $type); $Item->setValue($Value)->setExpiration($expiration); self::$Value->setValue($Item); try { $this->save(true); } catch (CasErrorException $Ex) { usleep(mt_rand(self::TIMEOUT_CAS_MINIMUM, self::TIMEOUT_CAS_MAXIMUM)); $this->set($field, $Value, $type, $expiration, $tries - 1); } } else { throw new CasErrorException('could not set value to cache'); } }
/** * Import item data method * @param array $data item data * @return Item self item */ private function import($data) { $this->field = (string) $data[0]; $this->type = (int) $data[1]; $this->expiration = (int) $data[2]; if ($this->type == 5) { $this->Value = new stdClass(); foreach ($data[3] as $nodeKey => $nodeValue) { $Item = new Item($nodeValue[0]); $this->Value->{$nodeKey} = $Item->import($nodeValue); } } else { $this->Value = $data[3]; } return $this; }