Memcache类(From ThinkPHP/Lib/Think/Util/Cache/CacheMemcache.class.php)
来源:互联网 发布:淘宝整点秒杀在哪里 编辑:程序博客网 时间:2024/06/01 19:26
/**
+------------------------------------------------------------------------------
* Memcache缓存类
+------------------------------------------------------------------------------
* @category Think
* @package Think
* @subpackage Util
* @author liu21st <liu21st@gmail.com>
* @version $Id$
+------------------------------------------------------------------------------
*/
class CacheMemcache extends Cache
{//类定义开始
/**
* 架构函数
*/
function __construct($options='')
{
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($options['host'], $options['port']) :
$this->handler->$func($options['host'], $options['port'], $options['timeout']);
$this->type = strtoupper(substr(__CLASS__,6));
}
/**
* 是否连接
*/
private function isConnected()
{
return $this->connected;
}
/**
* 读取缓存
*/
public function get($name)
{
return $this->handler->get($name);
}
/**
* 写入缓存
*/
public function set($name, $value, $ttl = null)
{
if(isset($ttl) && is_int($ttl))
$expire = $ttl;
else
$expire = $this->expire;
return $this->handler->set($name, $value, 0, $expire);
}
/**
* 删除缓存
*/
public function rm($name, $ttl = false)
{
return $ttl === false ?
$this->handler->delete($name) :
$this->handler->delete($name, $ttl);
}
/**
* 清除缓存
*/
public function clear()
{
return $this->handler->flush();
}
}//类定义结束
其中Cache类定义:
<?php
/**
+------------------------------------------------------------------------------
* 缓存管理类
+------------------------------------------------------------------------------
* @category Think
* @package Think
* @subpackage Util
* @author liu21st <liu21st@gmail.com>
* @version $Id$
+------------------------------------------------------------------------------
*/
class Cache extends Think
{//类定义开始
/**
* 是否连接
*/
protected $connected;
/**
* 操作句柄
*/
protected $handler;
/**
* 缓存存储前缀
*/
protected $prefix='~@';
/**
* 缓存连接参数
*/
protected $options = array();
/**
* 缓存类型
*/
protected $type;
/**
* 缓存过期时间
*/
protected $expire;
/**
* 连接缓存
*/
public function connect($type='memcache',$options=array())
{
$cachePath = dirname(__FILE__).'/Cache/';
$cacheClass = 'Cache'.ucwords(strtolower(trim($type)));
require_cache($cachePath.$cacheClass.'.class.php');
if(class_exists($cacheClass))
$cache = new $cacheClass($options);
else
throw_exception(L('_CACHE_TYPE_INVALID_').':'.$type);
return $cache;
}
public function __get($name) {
return $this->get($name);
}
public function __set($name,$value) {
return $this->set($name,$value);
}
public function __unset($name) {
$this->rm($name);
}
public function setOptions($name,$value) {
$this->options[$name] = $value;
}
public function getOptions($name) {
return $this->options[$name];
}
/**
* 取得缓存类实例
*/
static function getInstance()
{
$param = func_get_args();
return get_instance_of(__CLASS__,'connect',$param);
}
}//类定义结束
- Memcache类(From ThinkPHP/Lib/Think/Util/Cache/CacheMemcache.class.php)
- 几种常见的正则表达式验证(From ThinkPHP/Lib/Think/Core/Model.class.php)
- 【thinkphp3.x】ThinkPHP/Lib/Core/Think.class.php文件分析
- thinkPHP 框架 引导类Think.class.php 分析(一)
- thinkphp核心源码注释|Think.class.php
- thinkphp源码解析 (Version 3.1) -2 /Lib/Core/Think.class
- thinkphp核心源码注释|Cache.class.php
- [李景山php]thinkphp核心源码注释|Think.class.php
- /ThinkPHP/Library/Think/Storage/Driver/File.class.php LINE: 48
- /ThinkPHP/Library/Think/Storage/Driver/File.class.php LINE: 48
- [李景山php]thinkphp核心源码注释|Memcache.class.php
- Warning: require(/www/101/eduask_net/ThinkPHP/Library/Think/Think.class.php): failed to open stream:
- [李景山php]thinkphp核心源码注释|Cache.class.php
- thinkphp出现FILE: D:\www\zhao01\ThinkPHP\Library\Think\Dispatcher.class.php 解决方案
- 【thinkphp3.x】ThinkPHP/Lib/Core/App.class.php文件分析
- 【thinkphp3.x】ThinkPHP/Lib/Core/Dispatcher.class.php文件分析
- 【thinkphp3.x】ThinkPHP/Lib/Core/View.class.php文件分析
- 【thinkphp3.x】ThinkPHP/Lib/Behavior/ParseTemplateBehavior.class.php文件分析
- jQuery和CSS3定制HTML5视频播放器
- TortoiseSVN: 不能打开“C:\WINDOWS\TEMP\report.tmp”
- Mysql日期和时间函数大全
- 从零开始学习Sencha Touch MVC应用之七
- ubuntu安装eclispe adt
- Memcache类(From ThinkPHP/Lib/Think/Util/Cache/CacheMemcache.class.php)
- 如何在vc6下编译x264
- lucene界面索引的建立
- 从零开始学习Sencha Touch MVC应用之八
- Windows 通过公钥访问Git Server
- 一些link错误的解决方法(不断添加)
- 从零开始学习Sencha Touch MVC应用之九
- Java中文字编码问题详解
- 从零开始学习Sencha Touch MVC应用之十