Answer the question
In order to leave comments, you need to log in
How to cache a request by timer?
I have a costly new Query() query that counts a large amount of data that changes very quickly, therefore, when the query is called, it takes a long time to count, I would like it to remember it at the time of the response and be in the cache for 3 minutes then work again. How can this be implemented, can anyone give examples?
Answer the question
In order to leave comments, you need to log in
$query = Model::find()->where(['field' => 5, 'field2' => 777]);
$other = Yii::$app->db->cache(function ($db) use ($query) {
/** @var Connection $db */
return $db->createCommand($query->createCommand()->rawSql)->queryOne();
}, 120);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question