[Solved]Coutputcache's Varybysession Doesn't Behave


I overestimate varyBySession’s capabilities as once the user logs out sessionid goes empty for few requests. I have replaced my code to instead use:

'varyByExpression' => "(Yii::app()->user->isGuest)?Role::getIdByName('guest'):Yii::app()->user->roleId"

for such pages as components such as top menu and side menu are common across multiple users in same role.

I am using COutputFilter to cache an action that renders some static page files:

public function filters() {

        return array_merge(parent::filters(), array(


                'COutputCache +page',

                'cacheID' => 'pageCache',

                'duration' => 60*60*6,

                'varyBySession' => true,











    public function actions() {

        return array(

            'page' => array(

                'class' => 'CViewAction',





  • visit a static page with guest user

  • login and visit it again

  • logout and visit it, and you will see the page that loggedin users see with the side menu and top menu

I have verified that the session ids of loggedin and guest users are different each time throughout the scenario so varyBySession shall take care of it. There is no other caching enabled at this point.

Any ideas?