Yii Framework Forum: Page cahe - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Page cahe Rate Topic: -----

#1 User is offline   bogdanroxanutza 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 07-February 10

Posted 08 February 2010 - 10:05 AM

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 :)
0

#2 User is offline   sebas 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 496
  • Joined: 28-October 08
  • Location:Buenos Aires, Argentina

Posted 08 February 2010 - 01:52 PM

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');
       }
   } 

0

#3 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,889
  • Joined: 04-October 08
  • Location:DC, USA

Posted 08 February 2010 - 02:31 PM

http://www.yiiframew...de/caching.page
0

#4 User is offline   bogdanroxanutza 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 07-February 10

Posted 08 February 2010 - 03:43 PM

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!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users