Home >Backend Development >PHP Tutorial >How to enable fragment caching in Yii, enable fragments in yii_PHP tutorial
The example in this article describes how to enable fragment caching in Yii. Share it with everyone for your reference, the details are as follows:
1. Add:
to the components in the main.php filecache'=>array( 'class'=>'system.caching.CFileCache', ),
2. Add this sentence wherever caching is needed in the view
<?php if($this->beginCache('aaa', array( 'duration'=>3360, 'varyByParam'=>array('page'), 'dependecy'=>array( 'class'=> 'system.caching.CDbCacheDependency', 'sqll'=>'select count(server) from {{game_serve}}' , //设置依赖缓存,如果这个语句变化了,缓存跟新 ), ) ) ){ //这里是没有缓存走的,上面设置缓存时间,并且设置变化缓存,如果没有分页就不需要最后一个参数 } ?> //结束缓存这里,当没有缓存的时候走下面这if结尾也会缓存住信息,当前缓存在runtime文件夹中
Readers who are interested in more Yii-related content can check out the special topics on this site: "Introduction to Yii Framework and Summary of Common Techniques", "Summary of Excellent PHP Development Framework", "Basic Tutorial for Getting Started with Smarty Templates", "php Date and Time" Usage Summary", "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "php common database operation skills summary"
I hope this article will be helpful to everyone’s PHP program design based on the Yii framework.