Yii Framework Forum: Is Ok To Use Coutputcache And Chttpcachefilter Together? - Yii Framework Forum

Jump to content

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

Is Ok To Use Coutputcache And Chttpcachefilter Together? Rate Topic: -----

#1 User is offline   julianm 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 04-January 12

Posted 15 February 2013 - 03:05 PM

I am interested to speed up the pages for my application developed with Yii. I have been optimizing the DB queries, using yiilite.php, APC and now it is time to cache the pages.

I have been investigating about using CHttpCacheFilter and COutputCache. Both offers a good way to cache the entire page, but I could not find any reference about using both methods together.

In this case, what is the best way to enable page cache for guest users only? I noticed that when the user is logged out, the page is still cached.

Thanks.
0

#2 User is offline   Cstdenis 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 22-March 11

Posted 18 February 2013 - 03:52 AM

I don't see any reason why you couldn't use them both -- one is client side caching, the other server side.

For CHttpCacheFilter, once it's cached in the user's browser, it is staying there until it expires. The user logging out will not change anything there.


For differentiation between guests and logged in users, you probably want to use a duration of -1 for logged in users.

Quote

If it is a negative value, the cache will be disabled (any existing cached content will remain in the cache.)


'duration'=> Yii::app()->user->isGuest ? 86400 : -1,
1

#3 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 18 February 2013 - 08:14 AM

Being the original author of CHttpClientFilter I can assure you, there is nothing wrong with combining these cache methods. Just make sure that CHttpCacheFilter precedes COutputCache in the filter list.

As a general rule of thumb, it is actually bad to combine several caching methods as you end up with holding the cache content twice. But the nature of http caching evens that one out. The best scenario for the combination of these methods is content that is (1) hard to generate and (2) quite sizable.

I originally intended to write a wiki article concerning this and a few tips and tricks that go beyond CHttpCacheFilter's documentation. But oh well, my tight time budget recently ... ::)
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
2

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