WEBVTT

00:00.410 --> 00:03.170
So welcome back to the Knowledge Portal Video series.

00:03.350 --> 00:08.570
So in the last module, we have already discussed the two directives within the cache control header,

00:08.600 --> 00:11.930
which were the max age and max age.

00:13.400 --> 00:19.190
Today we are going to talk about the no cash and must revalidate directives.

00:20.390 --> 00:30.290
So taking our previous example again, so we have already seen this diagram in the last module where

00:31.010 --> 00:34.010
a client is requesting for a particular file.

00:35.940 --> 00:38.370
And the cash is getting the response.

00:38.370 --> 00:45.150
It is storing the file within the cache memory and also it is sending it to the browser.

00:46.120 --> 00:55.960
Now, we have also seen where we mentioned no store directive, which specifies that this particular

00:55.960 --> 01:02.350
file or document associated with a no store directive should not be stored either in the public cache

01:02.350 --> 01:04.420
or in the private cache.

01:05.580 --> 01:09.390
So there is one more important directive calls no cash.

01:10.160 --> 01:16.850
So no cash, as the name indicates, does not mean that do not store the cash.

01:17.150 --> 01:23.270
It just means that you are free to store the file in your cash.

01:23.270 --> 01:29.780
But whenever you serve it to the client, just revalidate it with the origin server, whether the file

01:29.780 --> 01:30.830
is fresh or not.

01:31.400 --> 01:35.150
So this is the only thing which no cache means.

01:35.780 --> 01:39.290
So let me show you in the.

01:40.210 --> 01:43.450
Enginex server so that it becomes much more clearer.

01:44.590 --> 01:52.630
So if we go into the Nginx configuration here, we have one header which is Cache-control, no store.

01:53.200 --> 01:55.150
So if we do a curl.

01:58.190 --> 02:03.230
And here you see the web server is responding with no store header.

02:04.680 --> 02:07.440
So if I go to example.com.

02:08.790 --> 02:11.040
Slash web three dot HTML.

02:12.300 --> 02:14.010
You see, the website has opened.

02:14.690 --> 02:17.750
Now if I go to about cash in the browser.

02:19.820 --> 02:22.010
And go to web three dot HTML.

02:22.820 --> 02:30.200
It will not find because the no store header has been introduced and this is the reason why Chrome is

02:30.200 --> 02:34.160
not storing this particular document inside its memory.

02:35.300 --> 02:36.380
Now.

02:39.300 --> 02:47.550
Let's comment out this header and let's add a new header which is cache-control.

02:48.030 --> 02:49.050
No cache.

02:53.390 --> 02:55.970
I'll save this and I'll reload the engines.

02:57.080 --> 03:00.580
Let's do a curl again to just verify.

03:00.590 --> 03:04.310
And now here we can see we have no cache header.

03:05.330 --> 03:10.370
So if we refresh the page, let's, let's open this page in one more tab.

03:11.510 --> 03:12.870
And the page has opened.

03:12.950 --> 03:15.350
So if we go to about cache now.

03:16.660 --> 03:19.090
And search for web three dot HTML.

03:19.210 --> 03:25.240
Now you see the Chrome has actually saved this particular document in its cache.

03:26.670 --> 03:34.290
Now, if I open this document, Chrome will have to revalidate it with the server again to make sure

03:34.290 --> 03:39.520
that this is the updated document and this is what no cache means.

03:39.540 --> 03:48.930
So every time I open this document, Chrome has to send a validation query back to the server asking

03:48.930 --> 03:54.030
whether this is the latest and the most fresh document which is available on the server.

03:55.810 --> 04:02.500
Now, there is one more important thing that we should remember that let's say a server has send a no

04:02.500 --> 04:08.800
cache and the document is stored both in the intermediary proxy as well as the browser cache.

04:09.070 --> 04:12.640
Now what happens if the origin server goes down?

04:13.780 --> 04:15.250
Then how will.

04:16.560 --> 04:21.270
A cash revalidate, whether the document is the latest or not.

04:21.810 --> 04:23.520
So that is a big question.

04:23.520 --> 04:29.730
So during that time, what happens is the cash will send a header college age with a warning saying

04:29.730 --> 04:33.390
that this is a stale document and I am serving you.

04:33.390 --> 04:34.350
The stale document.

04:34.350 --> 04:40.770
Stale basically means older version of the document, which cash is not very aware if that is the latest

04:40.770 --> 04:41.130
one.

04:43.010 --> 04:50.000
So many times requirement comes that you should not serve stale document at any cost.

04:50.390 --> 04:55.730
So during that time there is a header called as Must Revalidate, which comes into the picture.

04:56.660 --> 04:57.530
So.

05:01.750 --> 05:04.000
So talking about must revalidate.

05:04.000 --> 05:05.380
I'll add a header.

05:07.400 --> 05:11.630
See Cache control must revalidate.

05:13.580 --> 05:22.190
So this basically indicates that cash in no circumstances should send a stale document.

05:23.120 --> 05:28.670
And it should revalidate every time for a document freshness.

05:28.880 --> 05:34.550
So if a origin server is down due to some reason, then it should throw an error back and it should

05:34.550 --> 05:36.140
not serve a stale response.

05:36.260 --> 05:39.140
So this is very important thing to know.

05:41.270 --> 05:43.250
One more directive.

05:43.250 --> 05:50.060
We have already talked about the public and private, so let's see on how we can use this in conjunction

05:50.060 --> 05:51.470
with other headers.

05:51.530 --> 05:54.710
So I'll say add header cache control.

05:56.410 --> 05:56.600
I.

05:56.960 --> 05:58.360
I'll say private.

06:00.160 --> 06:03.040
Followed by Max H is equal to 200.

06:04.420 --> 06:06.790
So before we do this, let's just.

06:08.710 --> 06:10.300
Delete the older headers.

06:13.590 --> 06:14.160
Okay.

06:14.160 --> 06:17.970
So this basically means that.

06:20.160 --> 06:25.350
Cash control should be private, followed by max age of 200 seconds.

06:25.590 --> 06:26.950
I'll add one more header.

06:26.970 --> 06:29.850
This will be specific for the public proxies.

06:30.120 --> 06:39.780
I'll say cache control public followed by s max age is equal to let's assume 500 seconds.

06:42.260 --> 06:44.990
So this basically means that.

06:46.480 --> 06:52.120
For private cash, which basically can indicate browser related cash.

06:52.570 --> 06:58.690
Max age should be 200 seconds, and for public cash max, it should be 500 seconds.

06:58.990 --> 07:01.360
So this is how you can actually.

07:03.760 --> 07:05.350
Add multiple header fields.

07:05.350 --> 07:09.340
You can also add, say, cache control.

07:10.710 --> 07:14.310
First should be no cash as well as must revalidate.

07:20.770 --> 07:29.470
So this basically means that the browser or a cache server are free to store the document in its cache,

07:29.680 --> 07:35.410
but it should revalidate every time a request is received.

07:35.500 --> 07:40.750
So if the server is down, then you should not serve stale responses.

07:40.960 --> 07:48.790
So if we would have not included the revalidate header then a lot of cache servers will serve the stale

07:48.790 --> 07:50.710
responses if the server is down.

07:51.360 --> 07:54.510
So it is very important to remember this.

07:54.870 --> 08:00.630
So this is it about the non-cash as well as the revalidate header.

08:00.930 --> 08:04.630
So I hope this basic concept has been clear to you.

08:04.650 --> 08:07.860
I hope this has been informative for you and I'd like to thank you for.
