【问题标题】:How to Remove Cache of a Specific Page如何删除特定页面的缓存
【发布时间】:2015-01-12 05:39:25
【问题描述】:

当使用哨兵在 laravel 中实现身份验证并注销时,如果我按 '返回一页' 任何浏览器的按钮,它都会返回仪表板。如果页面被刷新,它会根据需要进入登录页面。但我想阻止在不刷新的情况下访问仪表板。

  1. 如何在登出后立即删除该特定页面的缓存?
  2. 如何找出任何浏览器的特定页面缓存以及 Laravel 的处理方法?

注意以这种方式注销并进入仪表板后,可以防止根据需要更改任何内容。

【问题讨论】:

    标签: php laravel caching browser


    【解决方案1】:

    调用注销函数时销毁会话。只需在控制器中编写注销功能,如下所示:

    public function getLogout() {
            Sentry::logout();
            Session::flush(); // Insert this line, it will  remove  all the session data
            return Redirect::to('users/login')->with('message', 'Your are now logged out!');
        }
    

    编辑:

    首先我只使用了 Session:flush(),但不知何故它奏效了!但是当我再次检查时,我发现它不起作用。所以,我们需要多加一些代码,在注销时清除浏览器缓存。

    使用过滤器可以解决这个问题。 (我还没有找到任何其他解决方案)首先,在filters.php中添加这段代码:

    Route::filter('no-cache',function($route, $request, $response){
    
        $response->header("Cache-Control","no-cache,no-store, must-revalidate");
        $response->header("Pragma", "no-cache"); //HTTP 1.0
        $response->header("Expires"," Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    
    });
    

    然后将此过滤器附加到路由或控制器。我将它附加到控制器的构造函数中,如下所示:

    public function __construct() {
            $this->beforeFilter('csrf',array('on' => 'post'));
            $this->afterFilter("no-cache", ["only"=>"getDashboard"]);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多