如何在yii2上缓存数据库翻译
我尝试了以下但没有工作
'i18n' => [
'class' => Zelenin\yii\modules\I18n\components\I18N::className(),
'languages' => ['en', 'ar', 'fr'],
'sourceMessageTable' => 'source_message',
'messageTable' => 'message',
'cache' => 'cache'
],
答案 0 :(得分:1)
问题出在Zelenin i18n模块中。如果你看一下Module.php文件,你可以看到:
$this->translations['*'] = [
'class' => DbMessageSource::className(),
'sourceMessageTable' => $this->sourceMessageTable,
'messageTable' => $this->messageTable,
'on missingTranslation' => $this->missingTranslationHandler
];
init()
方法中的。此代码设置了DbMessageSource选项,并且没有任何关于缓存的选项。模块也没有任何缓存选项。
如果您将此代码更改为:
$this->translations['*'] = [
'class' => DbMessageSource::className(),
'sourceMessageTable' => $this->sourceMessageTable,
'messageTable' => $this->messageTable,
'enableCaching' => true,
'cachingDuration' => 3600,
'on missingTranslation' => $this->missingTranslationHandler
];
缓存可行。一些SELECT
消息将从调试列表中消失。
答案 1 :(得分:-1)
Yii documentation for i18n db messages表示属性cache
仅在属性cacheDuration
不为零时才有意义。我建议你设置这个值,所以;
'i18n' => [
'class' => Zelenin\yii\modules\I18n\components\I18N::className(),
'languages' => ['en', 'ar', 'fr'],
'sourceMessageTable' => 'source_message',
'messageTable' => 'message',
'cache' => 'cache',
'cacheDuration' => 3600
],