Answer the question
In order to leave comments, you need to log in
Why is query caching not working?
Can you please tell me why caching does not work, what is required besides specifying the component in web.php?
$productsForFilter = Product::getDb()->cache(function ($db) use ($productQuery) {
return $productQuery->select('product.id')->asArray()->all();
});
Answer the question
In order to leave comments, you need to log in
one.
// Кэширование запросов для DAO
// Возвращает ассоциативный массив с именами столбцов и значений
$categories = Yii::$app->db->cache(function () {
return Yii::$app->db->createCommand('SELECT * FROM `category`')->queryAll();
});
// Кэширование запросов для ActiveRecord (на 1 час)
// Возвращает объект
$categories = Category::getDb()->cache(function (){
return Category::find()->all();
}, 3600);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question