鍍金池/ 問答/PHP  網(wǎng)絡(luò)安全/ Laravel 中有類似 Yii 2.0 中的 Schema 緩存嗎?

Laravel 中有類似 Yii 2.0 中的 Schema 緩存嗎?

Yii 2.0 性能優(yōu)化的文檔中看到 Schema 緩存的概念,內(nèi)容如下:

開啟 Schema 緩存

Schema 緩存是一個(gè)特殊的緩存功能, 每當(dāng)你使用活動(dòng)記錄時(shí)應(yīng)該要開啟這個(gè)緩存功能。如你所知, 活動(dòng)記錄能智能檢測數(shù)據(jù)庫對象的集合(例如列名、列類型、約束)而不需要手動(dòng)地描述它們。 活動(dòng)記錄是通過執(zhí)行額外的SQL查詢來獲得該信息。 通過啟用 Schema 緩存,檢索到的數(shù)據(jù)庫對象的集合將被保存在緩存中并在將來的請求中重用。

要開啟 Schema 緩存,需要配置一個(gè) cache 應(yīng)用組件來儲(chǔ)存 Schema 信息, 并在 配置 中設(shè)置 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 開發(fā)的一個(gè)內(nèi)部項(xiàng)目中嘗試了一下,真的明顯提升了速度,我想知道 Laravel 有沒有提供這個(gè) shema 緩存。

回答
編輯回答
笨笨噠

laravel 4.2的時(shí)候可以,這么寫

$users = DB::table('users')->remember(10)->get();

不過之后好像不可以了,參考這里

https://laracasts.com/discuss...

2017年1月27日 14:00
編輯回答
初心

Laravel5 中的 Eloquent ORM 的設(shè)計(jì)實(shí)現(xiàn)與 Yii2 的不一樣,不需要讀取數(shù)據(jù)庫的 Schema(呵呵,是好是壞自己評論)。因此就沒有 Schema 緩存這一說。
thinkphp 中也沒有這一說。

2017年4月6日 07:25