[Solved]Coutputcache's Varybysession Doesn't Behave

[size="5"]Resolved:[/size]

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(

            array(

                'COutputCache +page',

                'cacheID' => 'pageCache',

                'duration' => 60*60*6,

                'varyBySession' => true,

                'requestTypes'=>array('GET'),

                'dependency'=>array(

                        'class'=>'CExpressionDependency',

                        'expression'=>'filemtime(Yii::getPathOfAlias("webroot.themes.tentwentytwelve.views.site.pages.".Yii::app()->request->getParam("view")).".php")',

                    ),

                ),

            )

        );

    }


   

    public function actions() {

        return array(

            'page' => array(

                'class' => 'CViewAction',

            ),

        );

    }



Scenario:

  • 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?