在文件/protected/main.php里添加
‘components‘ => array(
‘CMemCache‘=>array(
‘class‘=>‘CMemCache‘,
‘servers‘=>array(
array(
‘host‘=>‘127.0.0.1‘,
‘port‘=>11211,
‘weight‘=>60,
),
array(
‘host‘=>‘127.0.0.1‘,
‘port‘=>11211,
‘weight‘=>40,
),
),
),
)
$cache = Yii::app()->CMemCache;
$cache->set("aa", 111);
分析源代码执顺序
YiiBase.php
public static function app()
{
return self::$_app;
}
CApplication.php
public function __construct($config=null)
{
Yii::setApplication($this);
CModule.php
public function __get($name)
{
if($this->hasComponent($name))
return $this->getComponent($name);
else
return parent::__get($name);
}
时间: 2024-10-07 18:29:49