如何在拉拉维尔注销后清除缓存



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

我已经浏览了很多堆栈上的链接,其中大多数建议在注销时清除标题,但它不起作用.

这是我尝试过的代码

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" />

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

谢谢

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

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

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

试试这个。

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');

在注销函数中清除缓存,将此代码放在那里

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

最新更新