本篇文章為大家展示了怎么在YII框架中實(shí)現(xiàn)頁面緩存,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
IndexController.php
namespace frontend\controllers; use yii; use yii\web\Controller; class IndexController extends Controller { public function behaviors()//先于action執(zhí)行,可以用來實(shí)現(xiàn)頁面緩存 { return [ [ 'class'=>'yii\filters\PageCache',//整個(gè)頁面緩存 'duration'=>10,//緩存時(shí)間 'only'=>['cache'],//只有index操作會(huì)被緩存,即使沒有視圖展示也會(huì)緩存 'dependency'=>[ 'class'=>'yii\caching\DbDependency', 'sql'=>'select count(*) from user', ], ] ]; } public function actionCache(){ //片段緩存 return $this->renderPartial("index"); } }
views/index/index.php
<?php $duration = 15; //緩存依賴 $dependency = [ 'class'=>'yii\caching\FileDependency', 'fileName'=>'hw.txt',//web目錄下 ]; //緩存的開關(guān) $enabled = false; ?> <?php //if($this->beginCache('cache_div',['duration' => $duration])){ //if($this->beginCache('cache_div',['enabled' => $enabled])){ if($this->beginCache('cache_div',['dependency' => $dependency])){?> <div id="cache_div"> <div>這里待會(huì)會(huì)被緩存 哈哈</div> </div> <?php $this->endCache(); }?> <div id="no_cache_div"> <div>這里不會(huì)被緩存 嚕</div> </div>
上述內(nèi)容就是怎么在YII框架中實(shí)現(xiàn)頁面緩存,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
網(wǎng)頁標(biāo)題:怎么在YII框架中實(shí)現(xiàn)頁面緩存-創(chuàng)新互聯(lián)
文章網(wǎng)址:http://jinyejixie.com/article22/hidjc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、網(wǎng)站制作、電子商務(wù)、Google、手機(jī)網(wǎng)站建設(shè)、App設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容