Answer the question
In order to leave comments, you need to log in
Does yii2 cache queries to the database by default?
The documentation says that the enableQueryCache flag is set to true by default;
And this is actually true, in the Connection class it is set to true;
Does this mean that now all requests generated using ActiveRecord are cached?
Or is this flag not enough and do you need to insert special commands into queries?
Those. if let's do it
$user = Profile::find()->where(["id" => $id])->asArray()->one();
Answer the question
In order to leave comments, you need to log in
Requests are cached if you explicitly call the method ->cache()
in the request.
$user = Profile::find()->where(["id" => $id])->cache(1000)->asArray()->one();
In other cases, requests are not cached. Sometimes, in the settings, schema caching is set:...
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=****',
'username' => '****',
'password' => '****',
'charset' => 'utf8',
'enableSchemaCache' => false, // Если не нужно кэшировать вместо `true` поставить `false`
'schemaCacheDuration' => 3600,
'schemaCache' => 'cache',
],
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question