Yii2 多组件缓存



如果在 Yii2 中使用多组件缓存并且在我的主.php中有这样的代码:

    'components' => [
        'schemaCache' => [
            'class' => 'yiicachingMemCache'
        ],
        'cache' => [
            'class' => 'yiicachingFileCache'
        ],

其中哪一个在缓存片段中使用?如何更改它?(例如,我通过MemCache缓存什么缓存模式,通过FileCache进行片段。

$this->cacheBegin('some_key')
缓存

片段使用yiiwidgetsFragmentCache类,默认情况下使用具有"cache"ID的组件。

因此,要全局更改此设置,您可以使用 DI 容器:

在你的索引中.php(入口脚本),在你包含 Yii 类文件之后

require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

添加以下行(将"fragmentCache"替换为所需的任何缓存组件 ID):

Yii::$container->set('yiiwidgetsFragmentCache', ['cache' => 'fragmentCache']);

最新更新