Answer the question
In order to leave comments, you need to log in
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
you should not do it through active record. Move the functionality of getting data into a separate component and use the cache there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question