如何删除特定页面的缓存

Nas*_*jim 5 php browser caching laravel

当使用sentry在raravel中实现身份验证并注销时,如果我按下任何浏览器的" 返回一页 "按钮,它将返回仪表板.如果刷新页面,则会根据需要转到登录页面.但是我希望在没有刷新的情况下阻止访问仪表板.

  1. 如何在注销后立即删除此特定页面的缓存?
  2. 如何找出任何浏览器的页面特定缓存和Laravel的做法?

注销并以此方式转到仪表板后,可以防止根据需要更改任何内容.

Tah*_*rar 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!');
    }
Run Code Online (Sandbox Code Playgroud)

编辑:

首先,我只使用 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

});
Run Code Online (Sandbox Code Playgroud)

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

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