【发布时间】:2015-01-14 12:42:04
【问题描述】:
我在引用指南:
``查询缓存是建立在数据缓存之上的一种特殊缓存功能。用于缓存数据库查询的结果。
查询缓存需要数据库连接和有效的缓存应用程序组件。查询缓存的基本用法如下,假设$db是一个yii\db\Connection实例:
$result = $db->cache(function ($db) {
// the result of the SQL query will be served from the cache
// if query caching is enabled and the query result is found in the cache
return $db->createCommand('SELECT * FROM customer WHERE id=1')->queryOne();
});
``
我不认为我会在 AR 类中手动创建数据库连接。那么如何在我的 AR 模型中做到这一点呢?
我在 yii2 论坛上问过the same question,但没有得到答复。似乎人们不知道如何在 Active Record 中进行查询缓存。
【问题讨论】:
标签: php mysql caching activerecord yii2