Is Ok To Use Coutputcache And Chttpcachefilter Together?

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.

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.

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

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