So welcome back to the Knowledge Portal Video series.
So in the last module, we have already discussed the two directives within the cache control header,
which were the max age and max age.
Today we are going to talk about the no cash and must revalidate directives.
So taking our previous example again, so we have already seen this diagram in the last module where
a client is requesting for a particular file.
And the cash is getting the response.
It is storing the file within the cache memory and also it is sending it to the browser.
Now, we have also seen where we mentioned no store directive, which specifies that this particular
file or document associated with a no store directive should not be stored either in the public cache
or in the private cache.
So there is one more important directive calls no cash.
So no cash, as the name indicates, does not mean that do not store the cash.
It just means that you are free to store the file in your cash.
But whenever you serve it to the client, just revalidate it with the origin server, whether the file
is fresh or not.
So this is the only thing which no cache means.
So let me show you in the.
Enginex server so that it becomes much more clearer.
So if we go into the Nginx configuration here, we have one header which is Cache-control, no store.
So if we do a curl.
And here you see the web server is responding with no store header.
So if I go to example.com.
Slash web three dot HTML.
You see, the website has opened.
Now if I go to about cash in the browser.
And go to web three dot HTML.
It will not find because the no store header has been introduced and this is the reason why Chrome is
not storing this particular document inside its memory.
Now.
Let's comment out this header and let's add a new header which is cache-control.
No cache.
I'll save this and I'll reload the engines.
Let's do a curl again to just verify.
And now here we can see we have no cache header.
So if we refresh the page, let's, let's open this page in one more tab.
And the page has opened.
So if we go to about cache now.
And search for web three dot HTML.
Now you see the Chrome has actually saved this particular document in its cache.
Now, if I open this document, Chrome will have to revalidate it with the server again to make sure
that this is the updated document and this is what no cache means.
So every time I open this document, Chrome has to send a validation query back to the server asking
whether this is the latest and the most fresh document which is available on the server.
Now, there is one more important thing that we should remember that let's say a server has send a no
cache and the document is stored both in the intermediary proxy as well as the browser cache.
Now what happens if the origin server goes down?
Then how will.
A cash revalidate, whether the document is the latest or not.
So that is a big question.
So during that time, what happens is the cash will send a header college age with a warning saying
that this is a stale document and I am serving you.
The stale document.
Stale basically means older version of the document, which cash is not very aware if that is the latest
one.
So many times requirement comes that you should not serve stale document at any cost.
So during that time there is a header called as Must Revalidate, which comes into the picture.
So.
So talking about must revalidate.
I'll add a header.
See Cache control must revalidate.
So this basically indicates that cash in no circumstances should send a stale document.
And it should revalidate every time for a document freshness.
So if a origin server is down due to some reason, then it should throw an error back and it should
not serve a stale response.
So this is very important thing to know.
One more directive.
We have already talked about the public and private, so let's see on how we can use this in conjunction
with other headers.
So I'll say add header cache control.
I.
I'll say private.
Followed by Max H is equal to 200.
So before we do this, let's just.
Delete the older headers.
Okay.
So this basically means that.
Cash control should be private, followed by max age of 200 seconds.
I'll add one more header.
This will be specific for the public proxies.
I'll say cache control public followed by s max age is equal to let's assume 500 seconds.
So this basically means that.
For private cash, which basically can indicate browser related cash.
Max age should be 200 seconds, and for public cash max, it should be 500 seconds.
So this is how you can actually.
Add multiple header fields.
You can also add, say, cache control.
First should be no cash as well as must revalidate.
So this basically means that the browser or a cache server are free to store the document in its cache,
but it should revalidate every time a request is received.
So if the server is down, then you should not serve stale responses.
So if we would have not included the revalidate header then a lot of cache servers will serve the stale
responses if the server is down.
So it is very important to remember this.
So this is it about the non-cash as well as the revalidate header.
So I hope this basic concept has been clear to you.
I hope this has been informative for you and I'd like to thank you for.