It is an action filter that can be added to a controller and handles the beforeAction event. To use PageCache, declare it in the behaviors() method of your controller class. In the following example the filter will be applied to the index action and cache the whole page for maximum 60 seconds or until the count of entries in the post table changes. It also stores different versions of the page depending on the application language. php public function behaviors() { return [ 'pageCache' => [ 'class' => 'yii\filters\PageCache', 'only' => ['index'], 'duration' => 60, 'dependency' => [ 'class' => 'yii\caching\DbDependency', 'sql' => 'SELECT COUNT(*) FROM post', ], 'variations' => [ \Yii::$app->language, ] ], ]; }
С версии: 2.0
Автор: Qiang Xue (qiang.xue@gmail.com)
Наследование: extends yii\base\ActionFilter
Пример #1
0
 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     if (!$this->enabled) {
         return true;
     }
     if (is_array($this->dependency)) {
         $this->dependency = Yii::createObject($this->dependency);
     }
     if ($this->dependency) {
         $oldDependency = $this->dependency;
         $tag = [$this->varyByRoute ? $action->getUniqueId() : __CLASS__];
         if (is_array($this->variations)) {
             foreach ($this->variations as $factor) {
                 $tag[] = $factor;
             }
         }
         $this->mutexDependency['tag'] = $tag;
         $this->dependency = ['class' => '\\yii\\caching\\ChainedDependency', 'dependOnAll' => false, 'dependencies' => [$oldDependency, Yii::createObject($this->mutexDependency)]];
     }
     return parent::beforeAction($action);
 }