Yii::createObject('cache',[
'class' => ...,
....
]);
<?php
define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require_once __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php';
$container = new \yii\di\Container;
$container->set('cache', [
'class' => 'yii\caching\FileCache',
'cachePath' => $_SERVER['DOCUMENT_ROOT'] . '/cache/',
'cacheFileSuffix' => '.xxx',
]);
$cache = $container->get('cache');
$container->set('connection', [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii2-app',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'queryCache' => $cache
]);
$connection = $container->get('connection');
$connection->open();
$q = "SELECT * FROM user_user";
$a = $connection->createCommand($q)->cache(45)->queryAll();