【php开源代码栏目提醒】:以下是网学会员为您推荐的php开源代码-CacheMemcache.class.php,希望本篇文章对您学习有所帮助。
<?php
// +----------------------------------------------------------------------
// | Think
PHP // +----------------------------------------------------------------------
// | Copyright (c) 2008 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// $Id$
/**
+------------------------------------------------------------------------------
* Memcache缂撳瓨绫?
+------------------------------------------------------------------------------
* @category Think
* @package Think
* @subpackage Util
* @author liu21st <liu21st@gmail.com>
* @version $Id$
+------------------------------------------------------------------------------
*/
class CacheMemcache extends Cache
{//绫诲畾涔夊紑濮?
/**
+----------------------------------------------------------
* 鏋舵瀯鍑芥暟
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
*/
function __construct($options='')
{
if ( !extension_loaded('memcache') ) {
throw_exception(L('绯荤粺涓嶆敮鎸乵emcache'));
}
if(empty($options)) {
$options = array
(
'host' => '127.0.0.1',
'port' => 11211,
'timeout' => false,
'persistent' => false
);
}
$func = $options['persistent'] ? 'pconnect' : 'connect';
$this->expire = isset($options['expire'])?$options['expire']:C('DATA_CACHE_TIME');
$this->handler = &new Memcache;
$this->connected = $options['timeout'] === false ?
$this->handler->$func($host, $port) :
$this->handler->$func($host, $port, $timeout);
$this->type = strtoupper(substr(__CLASS__,6));
}
/**
+----------------------------------------------------------
* 鏄惁杩炴帴
+----------------------------------------------------------
* @access private
+----------------------------------------------------------
* @return boolen
+----------------------------------------------------------
*/
private function isConnected()
{
return $this->connected;
}
/**
+----------------------------------------------------------
* 璇诲彇缂撳瓨
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $name 缂撳瓨鍙橀噺鍚?
+----------------------------------------------------------
* @return mixed
+----------------------------------------------------------
*/
public function get($name)
{
$this->Q(1);
return $this->handler->get($name);
}
/**
+----------------------------------------------------------
* 鍐欏叆缂撳瓨
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $name 缂撳瓨鍙橀噺鍚?
* @param mixed $value 瀛樺偍鏁版嵁
+----------------------------------------------------------
* @return boolen
+----------------------------------------------------------
*/
public function set($name, $value, $ttl = null)
{
$this->W(1);
if(isset($ttl) && is_int($ttl))
$expire = $ttl;
else
$expire = $this->expire;
return $this->handler->set($name, $value, 0, $expire);
}
/**
+----------------------------------------------------------
* 鍒犻櫎缂撳瓨
*
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $name 缂撳瓨鍙橀噺鍚?
+----------------------------------------------------------
* @return boolen
+----------------------------------------------------------
*/
public function rm($name, $ttl = false)
{
return $ttl === false ?
$this->handler->delete($name) :
$this->handler->delete($name, $ttl);
}
/**
+----------------------------------------------------------
* 娓呴櫎缂撳瓨
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @return boolen
+----------------------