Yii2缓存失效

时间:2017-02-02 12:39:28

标签: php yii2

我在我的前端/ SiteController.php

中有这个
public function actionPage($slug = 'home') {
    Url::remember();
    $val = Yii::$app->cache->getOrSet($slug, function() use ($slug) {
        $model = DBMenu::find()->with('pagesTranslations')->where(['slug' => $slug])->one();
        if ($model === null) {
            return $this->redirect(['/site/page', 'slug' => 'home']);
        }
        return $model;
    }, 0, new TagDependency(['tags' => 'page']));

    $searchModel = new Search();
    return $this->render('page',[
        'model' => $val,
        'searchModel' => $searchModel
    ]);
}

这条代码在backend / PageController.php

public function actionTest() {
    TagDependency::invalidate(Yii::$app->cache, 'page');
}

在我进入这个'测试'动作,然后转到网站/页面?slug = home我在日志中看到DB计数为50,它应该是68.为什么无效方法不起作用?

编辑: 通用/ config / main.php缓存设置如下:

'cache' => [
    'class' => 'yii\caching\FileCache',
],

0 个答案:

没有答案