I want to find difference between max-age alone and max-age with must-revalidate in Cache-Control header.
I did verification on chrome with both of these.
max-age=10 - It means that the response is no longer valid after 10 seconds and client has to reach to server to get the fresh result and should not serve the cached response or clear the response after 10 seconds.
max-age=10, must-revalidate - Here must-revalidate defines the same thing, but there can be 304 response from server and browser can use the cached data even after 10 seconds.
Assuming, difference with scenario 1, browser has to clear the cache and should expect fresh response from server, while in scenario 2 browser can keep the cached response and expect 304 status or fresh response.
But, practically in chrome above statements are not true, even if we respond with 403 chrome still serves the response from cache and by that mean there is no difference. Below is the code sample for rest api.
var ccpublicWrongResp = 3;
var ccpublicWrongRespCount = 0;
app.get('/ccpublic', function (req, res) {
console.log(req.url + " - " + new Date().getSeconds());
ccpublicWrongRespCount++;
if(ccpublicWrongRespCount >= ccpublicWrongResp){
console.log("Sending 304");
res.statusCode = (304);
res.send();
}else{
res.set('Cache-Control', 'public, max-age=12');
res.send("Please check after 12 seconds ");
}
});
var j = 1;
app.get('/mustrevalidate', function (req, res) {
console.log(req.url + " - " + new Date().getSeconds());
j++;
ccpublicWrongRespCount++;
if(ccpublicWrongRespCount >= ccpublicWrongResp){
console.log("Sending 304");
res.statusCode = (304);
res.send();
}else{
res.set('Cache-Control', 'public, max-age=12, must-revalidate');
res.send(j + " with must-revalidate");
}
});