Source for file Memcached.php
Documentation is available at Memcached.php
* @author Sotaro Karasawa <sotaro.k /at/ gmail.com>
* @version $Id: 1fbc96e645255b34b8b3d8f9e60bc75fb270f213 $
* キャッシュマネージャクラス(pecl::memcached 版)
* @author Sotaro Karasawa <sotaro.k /at/ gmail.com>
/**#@+ @access private */
/** @var object Memcached Memcached オブジェクト */
/** @var array plugin configure */
protected function _load()
if ($this->config['use_pconnect']) {
$this->m =
new Memcached($this->ctl->getAppId());
$this->m =
new Memcached();
$this->m->addServers($this->config['servers']);
$this->m->addServer($this->config['host'], $this->config['port']);
$this->m->setOption(Memcached::OPT_CONNECT_TIMEOUT, $this->config['timeout'] *
1000);
//$this->m->setOption(Memcached::OPT_CONNECT_TIMEOUT, $this->config['retry']);
* キャッシュに値が設定されている場合はキャッシュ値
* が戻り値となる。キャッシュに値が無い場合やlifetime
* を過ぎている場合、エラーが発生した場合はEthna_Error
* @param string $key cache key
* @param int $lifetime cache lifetime
* @param string $namespace namespace
public function get($key, $lifetime =
null, $namespace =
null)
$cache_key =
$this->_getCacheKey($namespace, $key);
if ($cache_key ==
null) {
$value =
$this->m->get($cache_key);
sprintf('no such cache, key="%s", message="%s"', $key, $this->m->getResultMessage()),
if ($lifetime !==
null) {
if (($time +
$lifetime) <
time()) {
* @param string $key cache key
* @param string $namespace cache namespace
$cache_key =
$this->_getCacheKey($namespace, $key);
if ($cache_key ==
null) {
$value =
$this->get($cache_key);
* @param string $key cache key
* @param int $lifetime lifetime
* @param string $namespace namespace
public function isCached($key, $lifetime =
null, $namespace =
null)
$r =
$this->get($key, $lifetime, $namespace);
* @param string $key cache key
* @param mixed $value cache value
* @param int $timestamp timestamp of last modified
* @param string $namespace namespace
* @param int $lifetime expiration
public function set($key, $value, $timestamp =
null, $namespace =
null, $expiration =
null)
$cache_key =
$this->_getCacheKey($namespace, $key);
if ($cache_key ===
null) {
$time =
$timestamp ?
$timestamp :
time();
$expiration =
$expiration ?
$expiration :
0;
if (!$this->m->set($cache_key, array('time' =>
$time, 'data' =>
$value), $expiration)) {
sprintf('failed to set cache, key="%s", message="%s"', $key, $this->m->getResultMessage()),
* @param string $key キャッシュキー
* @param string $namespace キャッシュネームスペース
public function clear($key, $namespace =
null)
$cache_key =
$this->_getCacheKey($namespace, $key);
if ($cache_key ===
null) {
if (!$this->m->delete($cache_key)) {
sprintf('failed to clear cache, key="%s", message="%s"', $key, $this->m->getResultMessage()),
* @param string $key キャッシュキー
* @param int $timeout ロックタイムアウト
* @param string $namespace キャッシュネームスペース
* @return bool true:成功 false:失敗
public function lock($key, $timeout =
5, $namespace =
null)
* @param string $key キャッシュキー
* @param string $namespace キャッシュネームスペース
* @return bool true:成功 false:失敗
public function unlock($key, $namespace =
null)
* set option of pecl::memcached directly
* @param string $opt option key
* @param string $value opeion value
* @see http://jp.php.net/manual/memcached.setoption.php
return $this->m->setOption($opt, $value);
* get option of pecl::memcached directly
* @param string $opt option key
* @see http://jp.php.net/manual/memcached.getoption.php
return $this->m->getOption($opt);
private function _getCacheKey($namespace, $key)
$cache_key =
$namespace .
"::" .
$key;
if (strlen($cache_key) >
250) {
Documentation generated on Fri, 11 Nov 2011 03:58:41 +0900 by phpDocumentor 1.4.3