Yii如何使用memcache缓存

在文件/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);

****************************************************************************

分析源代码执行顺序

frameework/YiiBase.php

public static function app(){return self::$_app;}CApplication.phppublic function __construct($config=null){Yii::setApplication($this);

始使化main.php 配置文件

framework/base/CModule.php$this->configure($config);foreach($config as $key=>$value){    $this->$key=$value;}

默认执行以下方法

setlanguage
sethomeUrl
settheme
setimport
setmodules
setcomponents
setparams

当访问到不存在的对象方法时,会调到下面文件里的方法

framework/base/CComponent.php

public function __set($name,$value){    if(method_exists($this,$setter)){    return $this->$setter($value);    }}