木子炜培先生

⑴2017底=>(年薪15万)=>31岁 ⑵2018=》(生产生活用品)并且年薪20万=>32岁 ⑶2019=>年薪30万=>把小作坊升级为工厂=>33岁 ⑷2020=>再开一个食品工厂

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

片段缓存

1 // ..../view/site/index.php页面
2 <?php 
3 if($this->beginCache('cache')) {
4     echo "<p class='cache'>这里待会会被缓存</p>";
5     $this->endCache();
6 }
7 echo "<p class='no_cache'>这里不会被缓存</p>";
8 ?>

 

 

 

 

 

 

 

 

 

 

 

片段缓存--过时间期

// ..../view/site/index.php页面 
<?php 
$duration = 15; // 设置过期秒数
if($this->beginCache('cache' , ['duration' => $duration])) {
    echo "<p class='cache'>这里待会会被缓存</p>";
    $this->endCache();
}
echo "<p class='no_cache'>这里不会被缓存</p>";
?>

片段缓存--依赖dependency

// ..../view/site/index.php页面 
<?php 
$dependency = [ // 这里用文件依赖举例
    'class' => '\yii\caching\FileDependency',
    'fileName' => 'robots.txt'
];
if($this->beginCache('cache' , ['dependency' => $dependency])) {
    echo "<p class='cache'>这里待会会被缓存</p>";
    $this->endCache();
}
echo "<p class='no_cache'>这里不会被缓存</p>";
?>

 循环嵌套片段缓存

// ..../view/site/index.php页面
<?php
if($this->beginCache('cache')) {
    // ...在此生成内容...
    if ($this->beginCache('cache')) {
        // ...在此生成内容...
        $this->endCache();
    }
    // ...在此生成内容...
    $this->endCache();
}
?>

 

posted on 2017-01-26 11:52  木子炜培先生  阅读(115)  评论(0编辑  收藏  举报