src/filters/PageCache.php
public function beforeAction($action)
    {
        if (!$this->enabled) {
            return true;
        }

        $this->cache = Instance::ensure($this->cache, Cache::className());

        if (is_array($this->dependency)) {
            $this->dependency = Yii::createObject($this->dependency);
        }

        $properties = [];
        foreach (['cache', 'duration', 'dependency', 'variations'] as $name) {
            $properties[$name] = $this->$name;
        }
        $id = $this->varyByRoute ? $action->getUniqueId() : __CLASS__;
        $response = Yii::$app->getResponse();
        ob_start();
        ob_implicit_flush(false);
        if ($this->view->beginCache($id, $properties)) {
            $response->on(Response::EVENT_AFTER_SEND, [$this, 'cacheResponse']);
            return true;
        } else {
            $data = $this->cache->get($this->calculateCacheKey());
            if (is_array($data)) {
                $this->restoreResponse($response, $data);
            }
            $response->content = ob_get_clean();
            return false;
        }
    }
public function beforeAction($action)
    {
        if (!$this->enabled) {
            return true;
        }

        $this->cache = Instance::ensure($this->cache, Cache::className());

        if (is_array($this->dependency)) {
            $this->dependency = Yii::createObject($this->dependency);
        }

        $properties = [];
        foreach (['cache', 'duration', 'dependency', 'variations'] as $name) {
            $properties[$name] = $this->$name;
        }
        $id = $this->varyByRoute ? $action->getUniqueId() : __CLASS__;
        $response = Yii::$app->getResponse();
        ob_start();
        ob_implicit_flush(false);
        if ($this->view->beginCache($id, $properties)) {
            $response->on(Response::EVENT_AFTER_SEND, [$this, 'cacheResponse']);
            return true;
        } else {
            $data = $this->cache->get($this->calculateCacheKey());
            if (is_array($data)) {
                $this->restoreResponse($response, $data);
            }
            $response->content = ob_get_clean();
            return false;
        }
    }
public function beforeAction ( $ action ) { if ( ! $ this -> enabled ) { return true ; } $ this -> cache = Instance :: ensure ( $ this -> cache , Cache :: className ( ) ) ; if ( is_array ( $ this -> dependency ) ) { $ this -> dependency = Yii :: createObject ( $ this -> dependency ) ; } $ properties = [ ] ; foreach ( [ 'cache' , 'duration' , 'dependency' , 'variations' ] as $ name ) { $ properties [ $ name ] = $ this -> $ name ; } $ id = $ this -> varyByRoute ? $ action -> getUniqueId ( ) : __CLASS__ ; $ response = Yii :: $ app -> getResponse ( ) ; ob_start ( ) ; ob_implicit_flush ( false ) ; if ( $ this -> view -> beginCache ( $ id , $ properties ) ) { $ response -> on ( Response :: EVENT_AFTER_SEND , [ $ this , 'cacheResponse' ] ) ; return true ; } else { $ data = $ this -> cache -> get ( $ this -> calculateCacheKey ( ) ) ; if ( is_array ( $ data ) ) { $ this -> restoreResponse ( $ response , $ data ) ; } $ response -> content = ob_get_clean ( ) ; return false ; } }
This method is invoked right before an action is to be executed (after all possible filters.)
You may override this method to do last-minute preparation for the action.
@param Action $action the action to be executed.
@return boolean whether the action should continue to be executed.
This method is invoked right before an action is to be executed ( after all possible filters . ) You may override this method to do last - minute preparation for the action .