Cache Concepts

i have put in Itemcontroller in some action


when that action is invoked it gives:

Fatal error: Call to a member function set() on a non-object in D:\xampp\htdocs\wwwroot\cart7\protected\controllers\ItemController.php on line 149

on my browser

my question is whether i should initialise or declare something please reply…

You need to configure a cache component, like e.g. CApcCache:











as you said i configured the configuration file

but i bot the following :



CApcCache requires PHP apc extension to be loaded.

Source File


00137:    /**

00138:      * Lists all models.

00139:      */


00141:    //called only once during startup


00143:    public function actionList()

00144:    {   


00146:        ItemTaken::model()->deleteAll();


00148:        $value1="kartik";

00149: Yii::app()->cache->set($value,"kartik");


00151:        //$cache=Yii::app()->cache;

00152:        //$cache['var1']="kartik";  // equivalent to: $cache->set('var1',$value1);

00153:        //$value2=$cache['var1'];  // equivalent to: $value2=$cache->get('var2');

00154:        echo "this is what cache contains" . $value;


00156:        $criteria=new CDbCriteria;                                    //creating instance of the criteria for condition


00158:        $pages=new CPagination(Item::model()->count($criteria));    //paging instance

00159:        $pages->pageSize=self::PAGE_SIZE;                            //setting the pase size

00160:        $pages->applyLimit($criteria);                                //applying the limit


Stack Trace

#0 D:\yii\framework\base\CModule.php(353): CApcCache->init()

#1 D:\yii\framework\base\CModule.php(91): CModule->getComponent('cache')

#2 D:\xampp\htdocs\wwwroot\cart7\protected\controllers\ItemController.php(149): CModule->__get('cache')

#3 D:\yii\framework\web\actions\CInlineAction.php(32): ItemController->actionList()

#4 D:\yii\framework\web\CController.php(300): CInlineAction->run()

#5 D:\yii\framework\web\filters\CFilterChain.php(129): CController->runAction(Object(CInlineAction))

#6 D:\yii\framework\web\filters\CFilter.php(41): CFilterChain->run()

#7 D:\yii\framework\web\CController.php(949): CFilter->filter(Object(CFilterChain))

#8 D:\yii\framework\web\filters\CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))

#9 D:\yii\framework\web\filters\CFilterChain.php(126): CInlineFilter->filter(Object(CFilterChain))

#10 D:\yii\framework\web\CController.php(283): CFilterChain->run()

#11 D:\yii\framework\web\CController.php(257): CController->runActionWithFilters(Object(CInlineAction), Array)

#12 D:\yii\framework\web\CWebApplication.php(332): CController->run('')

#13 D:\yii\framework\web\CWebApplication.php(120): CWebApplication->runController('')

#14 D:\yii\framework\base\CApplication.php(133): CWebApplication->processRequest()

#15 D:\xampp\htdocs\wwwroot\cart7\index.php(11): CApplication->run()

#16 {main}

2009-07-01 10:41:13 Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.9 Yii Framework/1.0.6

To use caching you need an underlying cache mechanism. Again see the caching overview in the guide to check which caches are supported by Yii.

One option is APC. It's an extension for PHP.  I'm not sure if it's included in XAMPP so it migh need separate installation. If it is included in XAMPP, then you only have to activate this extension in your php.ini:


i put the extension that you gave in php.ini file

but giving the same error

Then it’s obviously not included in XAMPP. This is not really a Yii issue so maybe just google for how to use APC + XAMPP.

You can also check the output of phpinfo() to see if APC is enabled. There's a section about APC if it's active.

thanks i will go through it…

yes i saw the yii/index.php file i executed it

it is showing failed in apc and mem cache extension.

so now i have to install apc or mem extension from . is it correct…

Yes. Or use another caching mechanism (File based, DB based, … see link above).