In Yii i've the main layout and the $content having changing so i do not need to cache it. My idea is to cache main layout
file (parts that wrap up $content, coming from view
files):
<?
$id= 'something';
if($this->beginCache($id, array('duration'=>3600, 'variations' =>array(Yii::$app->language)))) { ?>
<!DOCTYPE html>
<html>
<head>
...
<?php $this->endCache(); } // end of the upper cache piece ?>
<?php echo $content; ?>
<?php if($this->beginCache($id, array('duration'=>3600))) { // new cashe piece ?>
...
</body>
</html>
<?php $this->endCache(); } ?>
Settings:
config/main.php
'cache'=>array(
'class'=>'system.caching.CFileCache',
// 'connectionID'=>'db',
// 'autoCreateCacheTable'=>false,
// 'cacheTableName'=>'cache',
),
'memcache'=>array(
'class'=>'system.caching.CMemCache',
),
I've put cache filters() into the main controller:
components/Controller.php
class Controller extends CController
{
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
'postOnly + delete', // we only allow deletion via POST request
array(
'COutputCache',
'duration'=>1000,
'varyByParam'=>array('id'),
),
);
}
I'm not sure if i do it right way. My concern also is about $id
- what kind it should be? After some testing i found not a big performance increase... Would you comment/correct me?
Your Configuration file seems to be wrong. You have enabled 2 Cachings? CFileCache and CMemCache?
Look at the reference: http://www.yiiframework.com/doc/guide/1.1/en/caching.overview
The correct configuration should be:
'cache'=>array( 'class'=>'system.caching.CFileCache', ),
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.