【问题标题】:How To clear cache after logout In Laravel如何在 Laravel 中注销后清除缓存
【发布时间】:2020-05-13 05:15:09
【问题描述】:

这是一个常见的问题。当我注销然后单击浏览器后退按钮时,浏览器会显示网站最后加载的页面。

我浏览了堆栈上的许多链接,其中大多数建议在注销时清除标题,但没有成功。

这是我尝试过的代码

Route::get('main/logout',function(){


 Session::flush();
 Auth::logout();
 header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
 header("Pragma: no-cache"); // HTTP 1.0.
 header("Expires: 0"); // Proxies.
 session()->flash('alert-success', 'Success logged out');
 return Redirect::to('/');
}); 

更新

我也尝试将其添加到我的 APP.blade.php 文件的标题中

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="cache-control" content="no-store" />
<meta http-equiv="cache-control" content="must-revalidate" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />

如果你们有任何想法,请告诉我

谢谢

【问题讨论】:

    标签: google-chrome caching laravel-5


    【解决方案1】:

    您必须在用户返回的页面上包含以下行,而不是实际的注销页面:

    header("Cache-Control: no-cache, no-store, must-revalidate");
    

    但是这样你就失去了浏览器缓存的优势,在大多数情况下这不是一件好事。就这样吧。无论如何,用户在注销后无法与服务器交互,只能检索他已经看到的数据。

    【讨论】:

      【解决方案2】:

      试试这个。

      header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
      header("Cache-Control: post-check=0, pre-check=0", false);
      header("Pragma: no-cache");
      header('Content-Type: text/html');
      

      【讨论】:

        【解决方案3】:

        在你的注销函数中清除缓存,把这段代码放在那里

        Artisan::call('cache:clear');
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-01-16
          • 2019-06-19
          • 2017-02-16
          • 2018-05-01
          • 1970-01-01
          相关资源
          最近更新 更多