我在我的控制器中使用具有某些sql依赖性的PageCache类型。我需要一键重置缓存中的控制器。我该如何标记?
public function behaviors()
{
return [
[
'class' => 'yii\filters\PageCache',
'only' => ['category','index','tags','tag', 'post'],
'duration' => Yii::$app->params['blog_section'],
'variations' => [
Yii::$app->request->get('code'),
\Yii::$app->request->get('page'),
],
'dependency' => [
'class' => 'yii\caching\DbDependency',
'sql' => 'SELECT MAX(updated_at) FROM post',
],
],
];
}
答案 0 :(得分:1)
您可以将TagDependency
的ChainedDependency
与DbDependency
组合使用:
'dependency' => [
'class' => 'yii\caching\ChainedDependency',
'dependencies' => [
new \yii\caching\DbDependency([
'sql' => 'SELECT MAX(updated_at) FROM post',
]),
new \yii\caching\TagDependency([
'tags' => 'posts',
]),
],
],
当SELECT MAX(updated_at) FROM post
结果更改或名称为TagDependency
的{{1}}更改时,缓存将重新生效。您可以通过以下方式重新验证标签:
posts