在 Yii 2.0 性能优化的文档中看到 Schema 缓存的概念,内容如下:
开启 Schema 缓存
Schema 缓存是一个特殊的缓存功能, 每当你使用活动记录时应该要开启这个缓存功能。如你所知, 活动记录能智能检测数据库对象的集合(例如列名、列类型、约束)而不需要手动地描述它们。 活动记录是通过执行额外的SQL查询来获得该信息。 通过启用 Schema 缓存,检索到的数据库对象的集合将被保存在缓存中并在将来的请求中重用。
要开启 Schema 缓存,需要配置一个 cache 应用组件来储存 Schema 信息, 并在 配置 中设置 yiidbConnection::$enableSchemaCache 为 true :
return [
// ...
'components' => [
// ...
'cache' => [
'class' => 'yii\caching\FileCache',
],
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=mydatabase',
'username' => 'root',
'password' => '',
'enableSchemaCache' => true,
// Duration of schema cache.
'schemaCacheDuration' => 3600,
// Name of the cache component used to store schema information
'schemaCache' => 'cache',
],
],
];
我在公司用 Yii 2.0 开发的一个内部项目中尝试了一下,真的明显提升了速度,我想知道 Laravel 有没有提供这个 shema 缓存。
laravel 4.2的时候可以,这么写
不过之后好像不可以了,参考这里
https://laracasts.com/discuss...