简体   繁体   中英

Codeigniter caching when I have a session variable

I am facing a problem. I have a page where we have login button at the top of the page when the user logins in the login button changes into myaccount dropdown and loads the same page.

I am using caching in the controller where i load the view of the page to increase the speed. But the problem is when the user logins in the page with the login button is being loaded from the cache instead of the page with dropdown.

 <?php if($this->session->userdata('user_id') != ''){?>

 <ul class="nav nav-pills">

     <li class="dropdown pull-right">
                    <ul class="dropdown-menu">
                    <li><a href="<?php echo base_url();?>account-details"><i class="icon-briefcase icon-black"></i> Wallet</a></li>

                   <li><a href="<?php echo $this->session->userdata('logout')?>"><i class="icon-off icon-black"></i> Logout</a></li>                                                                                    
                     </ul>
                  </li>
              </ul>
           <?php }else{?>
                  <a href="<?php echo base_url();?>login_page/1" class="btn">Login / Sign Up</a>
                                                                    <?php
                                         }?>

    </div>

    </div>
    </div>

Don't cache session specific stuff.

Figure out which parts of the header are slow, and cacheable. Cache just those parts. You can also involve JavaScript to do some dynamic trickery but it gets real complicated real fast.

You can consider this two options,I think:

1.Don't use CI's generic caching, but use a cache library like http://philsturgeon.co.uk/code/codeigniter-cache

2.hack db_driver.php . On line 265 (CI 1.7.2) it checks if caching is enabled. Alter that line so it doesn't do it when it's a SELECT on the sessions table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM