Yii2缓存组件之数据库查询缓存

查询缓存

查询缓存是一个建立在数据缓存之上的特殊缓存特性。它用于缓存数据库查询的结果。PS:需配置好缓存配置

查询缓存需要一个 [[yii\db\Connection|数据库连接]] 和一个有效的cache应用组件。查询缓存的基本用法如下,假设$db是一个 [[yii\db\Connection]] 实例:

$duration = 60; // 缓存查询结果60秒 
$dependency = ...; // 可选的缓存依赖

$db->beginCache($duration, $dependency); 
// ...这儿执行数据库查询...
$db->endCache();

如你所见,beginCache()和endCache()中间的任何查询结果都会被缓存起来。如果缓存中找到了同样查询的结果,则查询会被跳过,直接从缓存中提取结果。

查询缓存可以用于ActiveRecordDAO

Info: 有些 DBMS (例如:MySQL)也支持数据库服务器端的查询缓存。你可以选择使用任一查询缓存机制。上文所述的查询缓存的好处在于你可以指定更灵活的缓存依赖因此可能更加高效。

来自GitHub Yii2中文文档

Responses
  1. Great items from you, man. I've take note your stuff prior to and you're simply extremely great. I actually like what you've bought here, certainly like what you're stating and the way during which you say it. You're making it entertaining and you still take care of to stay it smart. I can not wait to learn much more from you. This is actually a wonderful site.

    Reply
  2. This is the proper blog for anybody who desires to seek out out about this topic. You understand a lot its nearly arduous to argue with you (not that I actually would need匟aHa). You positively put a new spin on a subject thats been written about for years. Nice stuff, just nice!

    Reply
  3. [url=https://cialislh.com/]daily generic cialis[/url]

    Reply
  4. New super hot photo galleries, daily updated collections http://sallis.xnxxporn2go.amandahot.com/?destiney teen porn videos en formato french porn teen ass fucking hard core porn free miss molly 8 porn film sexpo asutralia picture porn

    Reply
  5. Pretty nice post. I just stumbled upon your blog and wished to say that I have really enjoyed surfing around your blog posts. In any case I will be subscribing to your feed and I hope you write again soon!

    Reply
  6. If you want to take a great deal from this piece of writing then you have to apply such methods to your won weblog.

    Reply