如何清除特定页面的缓存

5

在使用Sentry实现Laravel身份验证并注销后,如果我按下任何浏览器的'回到上一页'按钮,则会返回仪表板。如果刷新页面,则会按预期转到登录页面。但是我想防止在不刷新的情况下访问仪表板。

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

注销后以这种方式进入仪表板将无法对其进行更改。

1个回答

1

当您调用logout函数时,请销毁会话。只需在控制器中编写以下代码即可:

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"]);
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接