CFileCache:使用文件存储缓存数据。这个特别适合用于存储大块数据(例如页面)。注意,这个是从1.0.6版本开始支持的
CDbCache:使用一个数据表存储缓存数据。默认情况下,它将创建并使用在runtime目录下的一个SQLite3数据库
·CMemCache:使用PHP memcache扩展.
·CApcCache:使用PHP APC扩展.
配置文件:config.main.php
'components'=>array(
'Filecache'=>array(
'class'=>'system.caching.CFileCache'
),
'dbcache'=>array(
'class'=>'system.caching.CDbCache'
),
'memcache'=>array(//需要下载PHP拓展
'class'=>'system.caching.CMemCache',
'servers'=>array(
array(
'host'=>'127.0.0.1',
'port'=>'11211',
'weight'=>60,
),
array(
'host'=>'127.0.0.1',
'port'=>11211,
'weight'=>40
),
),
),
)
CCache类,常见的缓存操作方法get,set,add,delete,flush
控制器:Controller
public function actionIndex(){
echo "Index";
Yii::app()->dbcache->set("hello",'world',60);
Yii::app()->Filecache->set('aa','bb');
//Yii::app()->memcache->set('cc','dd',60); <span style="white-space:pre"> </span>//Yii::app()->cache->fulsh();清空缓存文件
<span style="white-space:pre"> </span>//Yii::app()->cache->delete($key);删除缓存
}
public function actionGetCache(){
echo 'GetCache<br>';
echo Yii::app()->dbcache->get('hello');
echo Yii::app()->Filecache->get('aa');
//echo Yii::app()->memcache->set('cc');
}
先访问index 再访问GetCache