You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Before I open this issue, I searched for hours in Github, Google and Yii forums
As explained in Yii2 documentations there are a way to cache queries using $db instance.
$result = $db->cache(function ($db) {
// the result of the SQL query will be served from the cache// if query caching is enabled and the query result is found in the cachereturn$db->createCommand('SELECT * FROM customer WHERE id=1')->queryOne();
});
But because I don't like write SQL code in ActiveRecord, how should implement query cache feature with ActiveRecord ?
Such as yii1 way:
$customer = newCustomer();
$cacheDependency = new yii\caching\DbDependency('SELECT MAX(...) FROM customer');
$custome->find()
->where(['id' => 1])
->cache(3600, $cacheDependency)
...
->one();
I searched about this issue and traced ActiveRecord where found I should override in yii\db\Query and change one() and all() methods.
For example current one() method in yii\db\Query is:
Before I open this issue, I searched for hours in Github, Google and Yii forums
As explained in Yii2 documentations there are a way to cache queries using
$db
instance.But because I don't like write SQL code in ActiveRecord, how should implement query cache feature with ActiveRecord ?
Such as yii1 way:
I searched about this issue and traced ActiveRecord where found I should override in
yii\db\Query
and changeone()
andall()
methods.For example current
one()
method inyii\db\Query
is:And must to be change to:
yii\base\ActiveQuery
:For
yii\base\Query
:Note: I didn't tested above codes
Am I in right way or there is cleaner solution to implement cache in ActiveRecords ?
The text was updated successfully, but these errors were encountered: