title: How to use query caching in yii2 ActiveRecord
body: <p>I am quoting the guide:</p>
  
  <p>``Query caching is a special caching feature built on top of data caching. It is provided to cache the result of database queries.</p>
  
  <p>Query caching requires a DB connection and a valid cache application component. The basic usage of query caching is as follows, assuming $db is a yii\db\Connection instance:</p>
  
  <pre><code>$result = $db-&gt;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-&gt;createCommand('SELECT * FROM customer WHERE id=1')-&gt;queryOne();
  
  });
  </code></pre>
  
  <p>``</p>
  
  <p>I do not think that I will manually create db connection in AR classes. So how to do this in my AR models ?</p>
  
  <p>I have asked <a href="http://www.yiiframework.com/forum/index.php/topic/61030-query-cashing-in-activerecord/" rel="nofollow">the same question</a> on yii2 forum but I got no answer. It seems that people do not know how to do query caching in Active Record.</p>