Question

I am building an API Server in node.js. I am doing requests from webapp (using guzzle) which is on different server to my api server. It is working ok. But at some times I get cached results from the api server. Also when sometimes there is 500 error response from api server. Those results are cached. how should I avoid such situations in my api server?

Was it helpful?

Solution

I simply had to pass some headers in middleware

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

OTHER TIPS

generate a random number and append with the request url everytime you request.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top