O
O
Oleg2018-11-26 23:39:28
Yii
Oleg, 2018-11-26 23:39:28

Yii2 how to set page cache dependency on two tables?

Good afternoon!
There is a CRUD controller for the model, let's say user, it organizes page caching through:

public function behaviors()
    {
        return [
            [
                'class' => 'yii\filters\PageCache',
                'duration' => 0,
                'variations' => [
                    Yii::$app->request->pathInfo,
                    Yii::$app->request->get(),
                    Yii::$app->language,
                ],
                'dependency' => [
                    'class' => 'yii\caching\DbDependency',
                    'sql' => 'SELECT MAX(updated_at) FROM user',
                ],
                'enabled' => Yii::$app->request->isGet
            ],
        ];
    }

Now the cache only depends on the last modification of the user table. In the view for index, I display data through the GridView, where there is a filter by the associated field, which is formed from a static function of another model:
...
[
                'attribute'=>'restaurant',
                'filter'=>Restaurant::nameArrayMap(),
                'value' => function ($model){
                   ...
                },
            ],
...

Question: how to make the page cache depend not only on changes to the main table, but also on the table used to build the filter?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question