Yii2 schemaCache配置无法生效

原创
小哥 5年前 (2022-05-12) 阅读数 3 #大杂烩
文章标签 Yii2schemaCache配置

在YII2中配置enableSchemaCache减少Schema的读取,从而提升数据库的性能,进而提升系统的整体性能,因此在线上的项目都会设置 enableSchemaCache => true。

 'enableSchemaCache' => true,
 'schemaCacheDuration' => 3600, // Duration of schema cache.
 'schemaCache' => 'redis', // Name of the cache component used to store schema information

和 schemaCache有关的主要是三个参数

  • enableSchemaCache 是否开启schema缓存
  • schemaCacheDuration schema缓存的时间,单位s
  • schemaCache 存储schema信息的缓存组件的名称

主要是 schemaCache这个配置,如果你不配置,Yii会找 cache组件,默认情况下是文件缓存的方式,如果,没有redis的效率高,因此 我们会将配置改为 'schemaCache' => 'redis' ,但是只是配置redis还不够,cache还必须实现yii\caching\CacheInterface 接口才可以 正确的配置为

'components' => [
    'cache' => [
            // 'class' => 'yii\caching\FileCache',
            'class' => 'yii\redis\Cache',
            'keyPrefix' => 'yiicache_',
        ], 
]
版权声明

所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除