我正在用laravel/vuejs构建React式 Jmeter 板。当 Jmeter 板工作并且套接字连接启动时,我的想法是用相同的用户ID同步所有客户端,在重新连接之后,我向端点发送请求,然后 synchronized
再一次。同步是必要的,因为所有用户实际上都可以将某些配置更改为 Jmeter 板,例如选择网格项或调整其大小或将其拖到另一个位置。
在重新连接到套接字之后,我向数据库发出请求以再次获取数据,并且得到与init请求相同的响应时,我正在挑战这个问题。数据未更新。
但当我再次断开连接时。数据再次同步。我正在更新第二次通话的数据。
我认为这是因为缓存控制头,但它没有授予我什么。
我试图更改api上的标题。
return response()->json($response, 200, [
'Cache-Control' => 'no-cache, no-store, must-revalidate'
]);
对于axios:
axios.get(payload.url, {
headers: {
'Content-Type': 'application/json',
'Cache-Control' : 'no-cache, no-store, must-revalidate'
}
}).then( response => {
但还是不行。
我雄辩的呼吁是:
$dashboards = Dashboard::where(
'user_id', '=', $userId
)->with([
'layouts',
'components' => function($query) {
$query->with('config')->with('type');
}
])->get();
第一次调用的标题如下:
Cache-Control: must-revalidate, no-cache, no-store, private
Connection: Keep-Alive
Content-Length: 2564
Content-Type: application/json
Date: Sat, 26 May 2018 12:06:34 GMT
Keep-Alive: timeout=5, max=96
Server: Apache/2.4.29 (Win32) OpenSSL/1.1.0g PHP/7.2.1
X-Powered-By: PHP/7.2.1
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 90
我接到的第二个电话
Cache-Control: must-revalidate, no-cache, no-store, private
Connection: Keep-Alive
Content-Length: 2564
Content-Type: application/json
Date: Sat, 26 May 2018 12:07:29 GMT
Keep-Alive: timeout=5, max=100
Server: Apache/2.4.29 (Win32) OpenSSL/1.1.0g PHP/7.2.1
X-Powered-By: PHP/7.2.1
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 94
为什么这个同步对第二个请求有效而不是第一个请求?
1条答案
按热度按时间xnifntxz1#
一切似乎都很好,可能是关于vue和异步操作调用。我设法在医生的帮助下把它修好了
Promise
. 但是,在使用浏览器历史记录(类似于chrome的浏览器)之后,缓存的问题也会出现。奇怪的是,标题出现在旧版本中Laravel
. 上面的标题以及max-age = 0
应该强制缓存刷新。