V
V
vitaly_742019-09-12 16:46:46
Yii
vitaly_74, 2019-09-12 16:46:46

Is it possible to execute frequent cached queries in yii2 db?

It's about the yii2 cache.
let's have a method like this

function tags(){
return Tags::find()->where(['status'=>1])->all();
}

Now I will give 2 cases.
1) call tags() multiple times
echo count($class->tags())
foreach ($class->tags() as $tag){
...
}

2) assign some variable $tags = $class->tags()
echo count($tags)
foreach ($tags as $tag ){
...
}

The question is whether two different methods differ greatly in terms of server load, given that in the first case the request is cached.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2019-09-12
@vitaly_74

What are cached queries in the database? There is a cache for this, so that these requests do not exist, and the data is taken from the cache!
Nobody does the way you try. Read about linked data and eager loading - the question, I think, will disappear.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question