本文整理汇总了PHP中Memcached::replaceByKey方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcached::replaceByKey方法的具体用法?PHP Memcached::replaceByKey怎么用?PHP Memcached::replaceByKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcached
的用法示例。
在下文中一共展示了Memcached::replaceByKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: replace
/**
* Replaces a value in cache.
*
* This method is similar to "add"; however, is does not successfully set a value if
* the object's key is not already set in cache.
*
* @link http://www.php.net/manual/en/memcached.replace.php
*
* @param string $key The key under which to store the value.
* @param mixed $value The value to store.
* @param string $group The group value appended to the $key.
* @param int $expiration The expiration time, defaults to 0.
* @param string $server_key The key identifying the server to store the value on.
* @param bool $byKey True to store in internal cache by key; false to not store by key
* @return bool Returns TRUE on success or FALSE on failure.
*/
public function replace($key, $value, $group = 'default', $expiration = 0, $server_key = '', $byKey = false)
{
$derived_key = $this->buildKey($key, $group);
$expiration = $this->sanitize_expiration($expiration);
// If group is a non-Memcached group, save to runtime cache, not Memcached
if (in_array($group, $this->no_mc_groups)) {
// Replace won't save unless the key already exists; mimic this behavior here
if (!isset($this->cache[$derived_key])) {
return false;
}
$this->cache[$derived_key] = $value;
return true;
}
// Save to Memcached
if (false !== $byKey) {
$result = $this->mc->replaceByKey($server_key, $derived_key, $value, $expiration);
} else {
$result = $this->mc->replace($derived_key, $value, $expiration);
}
// Store in runtime cache if add was successful
if (Memcached::RES_SUCCESS === $this->getResultCode()) {
$this->add_to_internal_cache($derived_key, $value);
}
return $result;
}
示例2: replaceByKey
/**
* @inheritdoc
*/
public function replaceByKey($server_key, $key, $value, $expiration = null)
{
$key = $this->prefix . $key;
return parent::replaceByKey($server_key, $key, $value, $expiration);
}