本文整理汇总了PHP中Memcache::replace方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcache::replace方法的具体用法?PHP Memcache::replace怎么用?PHP Memcache::replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcache
的用法示例。
在下文中一共展示了Memcache::replace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* Save getting data to memory (RAM)
*/
public function save()
{
$this->storage_data['last_update'] = $this->last_update;
if ($this->memcache->replace('storage_data', $this->storage_data) === false) {
$this->memcache->add('storage_data', $this->storage_data);
}
}
示例2: replace
function replace($key, $value, $ttl = 0)
{
$key = str_replace('\\', '/', $key);
if (!$this->memcache->replace($key, $value, false, $ttl)) {
$message = sprintf('Memcache::replace() with key "%s" failed', $key);
\ManiaLib\Utils\Logger::error($message);
}
}
示例3: add
/**
* 添加一个缓存
*
* 修改为: 强制设置,强制过期
*
* @param string $key 缓存键
* @param mix $value 缓存值
* @param string $flag 是否压缩 MEMCACHE_COMPRESSED(2)使用zlib压缩
* @param int $expire 过期时间,0永不过期,最大30天(2592000) 或unix时间戳
*/
public function add($key, $value, $flag = FALSE, $expire = 0)
{
if (!$this->connect->add($this->prefix . $key, $value, $flag, $expire)) {
//只能新添加一个值,重复刷新不会覆盖
return $this->connect->replace($this->prefix . $key, $value, $flag, $expire);
//必须是已存在的,不存在的会导致设置失败
}
return true;
}
示例4: put
/**
* {@inheritdoc}
*/
public function put($key, $data, $ttl = 0)
{
if ($ttl !== 0) {
$ttl += time();
}
if ($this->memcache->replace($key, $data, $this->compressionLevel, $ttl) === false) {
return $this->memcache->set($key, $data, $this->compressionLevel, $ttl);
}
return true;
}
示例5: set
/**
* @see \Kalibri\Cache\BaseInterface::set();
*/
public function set($key, $value, $expire = 0)
{
if (\Kalibri::config()->get('debug.log.is-enabled', false)) {
\Kalibri::logger()->add(\Kalibri\Logger\Base::L_DEBUG, "SET: (ttl={$expire}) {$key}=" . var_export($value, true), $this);
}
if (!$this->_memcache->replace($key, $value, MEMCACHE_COMPRESSED, $expire)) {
$this->_memcache->set($key, $value, MEMCACHE_COMPRESSED, $expire);
}
$this->_local[$key] = $value;
return $this;
}
示例6: write
/**
* {@inheritdoc}
*/
public function write($sessionId, $data)
{
if (!$this->memcache->replace($this->prefix . $sessionId, $data, 0, $this->memcacheOptions['expiretime'])) {
return $this->memcache->set($this->prefix . $sessionId, $data, 0, $this->memcacheOptions['expiretime']);
}
return true;
}
示例7: add_record
/**
* Adds entry into memcache/apc DB.
*
* @param string $key Cache key name
* @param mxied $data Serialized cache data
* @param bollean $index Enables immediate index update
*
* @param boolean True on success, False on failure
*/
private function add_record($key, $data, $index = false)
{
if ($this->type == 'memcache') {
$result = $this->db->replace($key, $data, MEMCACHE_COMPRESSED, $this->ttl);
if (!$result) {
$result = $this->db->set($key, $data, MEMCACHE_COMPRESSED, $this->ttl);
}
} else {
if ($this->type == 'apc') {
if (apc_exists($key)) {
apc_delete($key);
}
$result = apc_store($key, $data, $this->ttl);
}
}
// Update index
if ($index && $result) {
$this->load_index();
if (array_search($key, $this->index) === false) {
$this->index[] = $key;
$data = serialize($this->index);
$this->add_record($this->ikey(), $data);
}
}
return $result;
}
示例8: unlock
/**
* Unlock cached item - override parent for cacheid compatibility with lock
*
* @param string $id The cache data id
* @param string $group The cache data group
*
* @return boolean True on success, false otherwise.
*
* @since 11.1
*/
public function unlock($id, $group = null)
{
$cache_id = $this->_getCacheId($id, $group) . '_lock';
if (!$this->lockindex())
{
return false;
}
$index = self::$_db->get($this->_hash . '-index');
if ($index === false)
{
$index = array();
}
foreach ($index as $key => $value)
{
if ($value->name == $cache_id)
{
unset($index[$key]);
}
break;
}
self::$_db->replace($this->_hash . '-index', $index, 0, 0);
$this->unlockindex();
return self::$_db->delete($cache_id);
}
示例9: replace
/**
* 替换k存储的值,当k不存在时返回FALSE
* @param mixed $v 将要替换存储的值。字符串和整型被以原文存储,其他类型序列化后存储
* @param string $compress 为TRUE时使用 MEMCACHE_COMPRESSED 标记对数据进行压缩(使用zlib)。
* @param number $expire 写入缓存的数据的失效时间。如果此值设置为0表明此数据永不过期。可以设置一个UNIX时间戳或以秒为单位的整数(从当前算起的时间差)来说明此数据的过期时间,但是在后一种设置方式中,不能超过 2592000秒(30天)。
* @return bool 成功时返回TRUE,当k不存在时返回FALSE
*/
public function replace($v, $expire = 0, $compress = FALSE)
{
if ($expire <= 0) {
return FALSE;
}
return $this->mc->replace($this->k, $v, $compress, $expire);
}
示例10: set
/**
* Set/add something to the cache
*
* @param string $key Key for the value
* @param mixed $value Value
* @return boolean
*/
public function set($key, $value)
{
if ($this->cache->add($key, $value, $this->compression, $this->expire)) {
return true;
}
return $this->cache->replace($key, $value, $this->compression, $this->expire);
}
示例11: read
/**
* Read from cache.
* @param string key
* @return mixed|NULL
*/
public function read($key)
{
$key = $this->prefix . $key;
$meta = $this->memcache->get($key);
if (!$meta) {
return NULL;
}
// meta structure:
// array(
// data => stored data
// delta => relative (sliding) expiration
// callbacks => array of callbacks (function, args)
// )
// verify dependencies
if (!empty($meta[self::META_CALLBACKS]) && !NCache::checkCallbacks($meta[self::META_CALLBACKS])) {
$this->memcache->delete($key, 0);
return NULL;
}
if (!empty($meta[self::META_DELTA])) {
$this->memcache->replace($key, $meta, 0, $meta[self::META_DELTA] + time());
}
return $meta[self::META_DATA];
}
示例12: replace
public function replace($key, $data, $expire = 0)
{
if (!isset($this->memcache)) {
$this->connect();
}
$key = $this->prefix . $key;
return $this->memcache->replace($key, $data, $expire);
}
示例13: saveConfiguration
public function saveConfiguration($namespace, $context, $language, $environment, $name, Configuration $config)
{
$name = $this->remapConfigurationName($name);
// saving the configuration always includes saving in both the
// persistent file and the memcached store!
$key = $this->getStoreIdentifier($namespace, $context, $language, $environment, $name);
$this->memcachedService->replace($key, $config, 0, $this->expireTime);
ConfigurationManager::saveConfiguration($namespace, $context, $language, $environment, $name, $config);
}
示例14: afterSave
public function afterSave(Atomik_Model_Builder $builder, Atomik_Model $model)
{
$key = $builder->name . ':' . $model->getPrimaryKey();
$data = $model->toArray();
if ($this->_memcache->replace($key, $data) === false) {
$this->_memcache->set($key, $data);
}
}
示例15: touch
/**
* 更新过期时间
*
* @return void
*/
public function touch()
{
if (null !== $this->_sessionId && $this->_expire) {
// we try replace() first becase set() seems to be slower
if (!($result = $this->_memcache->replace($this->_sessionId, $this->_session, 0, $this->_expire))) {
$result = $this->_memcache->set($this->_sessionId, $this->_session, 0, $this->_expire);
}
}
}