Page cahe

Hello!

Could someone give me an example about how i can cache a page for 1 hour (3600) … ?

I want to cache my front page of the website (http://example.com), the entire page.

Thank you :)

This should work:




   function actionIndex(){

       if (isset(Yii::app()->cache)){

            $data = Yii::app()->cache->get('homepage');

            if($data==null){

                   $data = $this->render('index', array(), true);

                   Yii::app()->cache->set('homepage', $data, 3600);

            }

            echo $data;

       }else{

            $this->render('index');

       }

   } 



http://www.yiiframework.com/doc/guide/caching.page

Thank you for your replies!

Ok, sebas i have a question: i like your method, i understand it but i don’t understand why the page isn’t cached?

I made a test on a standard generated web page, everything is good when the line “$this->render(‘index’);” is there but when i commented it i don’t get any cached page(any content), only a blank page.

I just switched from code igniter to yii and i really appreciate if you can help me a little bit with this problem.

Thank you!