Yii Framework Forum: [Solved]Coutputcache's Varybysession Doesn't Behave - Yii Framework Forum

Jump to content

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

[Solved]Coutputcache's Varybysession Doesn't Behave Rate Topic: -----

#1 User is offline   shoaibi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 08-June 11
  • Location:Islamabad, Pakistan

Posted 07 December 2012 - 12:37 AM

Resolved:
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?
0

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