$db = User::getDb();
$dep = new DbDependency();
$dep->sql = "SELECT MAX(updated_at) FROM user";
$result = $db->cache(function ($db) {
return User::find()->all($db);
}, 600, $dep);
$cache = $this->cache; // Could be Yii::$app->cache
return $cache->getOrSet(['top-n-products', 'n' => $count], function ($cache) use ($count) {
return Products::find()->mostPopular()->limit(10)->all();
}, 1000);