我正在node.js中构建一个API服务器。我正在做webapp(使用guzzle)的请求,它位于我的api服务器的不同服务器上。它工作正常。但有时我从api服务器获得缓存结果。此外,有时有来自api服务器的500错误响应。这些结果被缓存。我该怎样在api服务器中避免这种情况?
答案 0 :(得分:0)
我只需要在中间件中传递一些标题
function setHeaders(req, res, next) {
res.set({
'cache-control': 'max-age=0, no-cache, no-store, must-revalidate',
'expires': 0,
'pragma': 'no-cache'
});
}
app.use(setHeaders);
答案 1 :(得分:-1)
生成一个随机数,并在每次请求时附加请求网址。