I want to do full page caching in my application with COutputCache as a filter as in the example in the Page Caching chapter in the guide.
However, I only want to cache pages from guest (not logged in) visitors (full page caching for members would take too much space in the cache causing more useful stuff to get pushed out. Instead they get only some resource-intensive fragments/data items cached).
I can not find any way to do this.
I was hoping I could do it with something like this
array('COutputCache',
'duration'=>86400,
'requestTypes'=>array('GET'),
'dependency'=>
array(
'class'=>'CExpressionDependency',
'expression'=>'$_SESSION["user"]->isGuest',
),
),
but it looks like this would cache 2 copies, one for guest, one for logged in.
What I need is something like requestTypes except allowing an arbitrary expression instead of just GET/POST.
I potentially have the same problem with CDbCacheDependency. If I have an expression like the example
'dependency'=>array(
'class'=>'system.caching.dependencies.CDbCacheDependency',
'sql'=>'SELECT MAX(lastModified) FROM Post'
)
is it smart enough to delete the old cache version when the lastModified date gets bumped, or does it make a new one and leave the old one there wasting space?
How can I do this?
I may be able to work around this by using renderDynamic() for the content that varies for guest/member but this would end up adding quite a bit of complexity (multiple items vary) and wouldn’t provide as much of a performance boost because those content fragments would still need to be calculated for guests.