R
R
Ruslan Kasymov2014-07-24 15:47:31
Yii
Ruslan Kasymov, 2014-07-24 15:47:31

How to cache related data in YII?

I use caching in the model like this:
$posts = Post::model()->cache(1000)->findAll();
$posts = Post::model()->cache(1000)->with('author')->findAll();
In the first case, everything in $posts will be cached, but $posts->author is no longer there... What to do? You can of course get confused and do it through
Yii::app()->cache->set()and Yii::app()->cache->get()
But I want to do it through Active Record ... But how?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2014-07-24
Protko @Fesor

you should not do it through active record. Move the functionality of getting data into a separate component and use the cache there.

R
Ruslan Kasymov, 2014-07-24
@HDAPache

Why not? What is bad practice?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question