When query caching is enabled ([[enableQueryCache]] is true and [[queryCache]] refers to a valid cache),
queries performed within the callable will be cached and their results will be fetched from cache if available.
For example,
php
The customer will be fetched from cache if available.
If not, the query will be made against DB and cached for use next time.
$customer = $db->cache(function (Connection $db) {
return $db->createCommand('SELECT * FROM customer WHERE id=1')->queryOne();
});
Note that query cache is only meaningful for queries that return results. For queries performed with
[[Command::execute()]], query cache will not be used.