WEBVTT

00:00.440 --> 00:06.590
So in the last module we were discussing about the basics of the cache control header and the directives

00:06.830 --> 00:10.010
for the newer Http 1.1 protocol.

00:10.370 --> 00:17.750
So today we are going to talk in detail about the cache control header directives and two of the important

00:17.750 --> 00:20.810
directives are max age and max age.

00:22.010 --> 00:24.860
So revising our concepts on caching.

00:25.810 --> 00:32.830
So if a browser requests for a particular document and if there is an intermediary proxy in between,

00:32.860 --> 00:37.030
then the request first goes to the cache proxy over here.

00:37.120 --> 00:42.760
The cache proxy will try to validate if the file is present within the proxy memory.

00:43.030 --> 00:51.670
If it is not present, then the proxy will forward the request to the origin server where the file is

00:51.670 --> 00:52.420
present.

00:54.300 --> 00:59.970
Now, in response, the Origin server will send the file back to the cache server.

01:00.570 --> 01:06.090
Cache server will store the file depending upon the cache control headers, which origin server has

01:06.090 --> 01:10.290
sent, and it will also send the file back to the client.

01:11.660 --> 01:15.770
Now there are two important concepts that are important to know over here.

01:17.000 --> 01:20.240
The concepts of public and private cash.

01:21.350 --> 01:28.730
So if we talk about this intermediary cash server, it can happen that within an organization there

01:28.730 --> 01:36.980
is one intermediary cash server and that actually does the cashing of, say, 200 users within an organization.

01:37.540 --> 01:45.700
So essentially this cache server is being used by multiple users, so this can be considered as public

01:45.700 --> 01:46.360
cache.

01:47.350 --> 01:52.000
However, we know that even browser has its own cache memory.

01:52.840 --> 01:56.860
And that cash is private to a particular user.

01:56.860 --> 01:59.800
And this is why it is called as private cash.

02:00.250 --> 02:03.550
So again, revising we have two important concepts.

02:03.550 --> 02:06.550
One is public cash and one is private cash.

02:08.880 --> 02:15.540
So talking about the max age and max age directives within the cache control header.

02:17.110 --> 02:21.940
We have a in the cache control max age is equal to 120.

02:21.970 --> 02:25.850
So this 120 is basically the timeline in seconds.

02:25.870 --> 02:34.810
So if a nginx or if a web server sends along with a document, this directive which is cache-control

02:34.810 --> 02:36.730
max age is equal to 120.

02:36.760 --> 02:44.470
So it basically determines that the web server is saying to the cache proxy, both public and private,

02:44.500 --> 02:50.170
to consider this document as fresh for one 20s.

02:51.130 --> 03:00.130
After one 20s This document will not be considered fresh and it will ask the cache to revalidate it.

03:02.020 --> 03:06.610
Now there is a second header college s max age.

03:06.640 --> 03:11.830
Now s max age is specifically for the intermediary cache servers.

03:12.920 --> 03:19.190
So let's assume for a particular file there are two headers which are sent, which is Max H is equal

03:19.190 --> 03:22.220
to 120 and S max is is equal to 200.

03:22.490 --> 03:32.480
So what it will mean is it will mean that the public cache server should store this file for 200 seconds

03:32.480 --> 03:34.130
before it gets stale.

03:35.030 --> 03:41.690
However, for private cache, the file should be considered as fresh only for one 20s.

03:42.050 --> 03:46.100
So these are directives specifically for public and private cache.

03:47.690 --> 03:52.130
So let's go back to our links and see on how exactly it works.

03:54.230 --> 04:01.670
So let's let me do a curl on width to show the headers for http example.com.

04:03.570 --> 04:04.570
One dot HTML.

04:06.040 --> 04:11.710
So here, if we see there are no cache control headers which are present, even the expired header is

04:11.710 --> 04:12.690
not present.

04:12.700 --> 04:17.680
So the web server specifically is not saying when the document will expire.

04:18.790 --> 04:26.080
So during this cases, the browser will have its own heuristic method to determine the expiration time.

04:27.520 --> 04:31.270
So let's go to the Enginex configuration.

04:33.770 --> 04:37.550
And let's mention our first cache control header.

04:38.270 --> 04:41.030
So I'll say add header.

04:42.100 --> 04:44.680
So this is basically used for adding the header.

04:45.420 --> 04:46.710
Saying cash.

04:47.470 --> 04:52.450
Control followed by Max H is equal to 120.

04:53.860 --> 05:02.020
So this basically means that any document that ends with Dot HTML will have a cache control header with

05:02.020 --> 05:06.520
a directive max hyphen age is equal to one 20s.

05:07.510 --> 05:11.120
So I'll save this and let's reload the nginx.

05:13.780 --> 05:15.760
And if we do a curl again.

05:16.060 --> 05:16.720
Curl.

05:16.720 --> 05:25.480
I say example.com one dot HTML and now you have seen the cache control header with max.

05:25.480 --> 05:28.030
Age is equal to one 20s has been added.

05:29.290 --> 05:36.520
So let's open our favorite wireshark and let's clear this up and let's start a new packet capture.

05:37.240 --> 05:48.940
Okay, I'll go to my chrome and I'll say Http or I'll say example.com web one dot HTML.

05:52.230 --> 05:54.790
And this is a simple website which has been loaded.

05:54.810 --> 05:56.940
So if I go to about cash.

06:00.250 --> 06:08.650
And let's filter it on Web one dot HTML and let's click here and it will basically give us the.

06:10.070 --> 06:11.570
Headers that it has received.

06:11.690 --> 06:17.290
And here you can see cache control where Max hyphen age is one 20s.

06:17.300 --> 06:23.260
So this basically instructs Chrome that this document is valid only for one 20s.

06:23.270 --> 06:29.630
And after this time has expired, the Chrome should again revalidate with the server to check the freshness

06:29.630 --> 06:31.550
of a particular document.

06:32.550 --> 06:40.110
Okay, so now let's go back to the Nginx and let's look at.

06:44.000 --> 06:45.260
One more directive.

06:49.670 --> 06:52.790
So I'll comment the first one out.

06:54.290 --> 06:58.430
And as it's very interrelated with the.

07:00.630 --> 07:02.280
Cache-control Max age.

07:02.280 --> 07:02.690
I'll.

07:04.260 --> 07:05.940
At this in this video itself.

07:05.940 --> 07:08.730
So it's no store.

07:11.560 --> 07:18.800
So what does no store means is that do not store this particular document in cache.

07:18.820 --> 07:25.240
So this specifies both the public as well as private cache servers do not store this document at all.

07:25.990 --> 07:28.150
So let's see on how it works.

07:28.150 --> 07:30.340
So I'll save the Nginx.

07:30.490 --> 07:31.570
I'll do reload.

07:32.970 --> 07:34.740
Let's do a curl again.

07:37.510 --> 07:39.490
Let's open up one more document.

07:39.490 --> 07:46.930
And here, if we see the web server is sending no stored directives along with the web two dot HTML

07:46.930 --> 07:47.200
file.

07:48.370 --> 07:49.300
Now.

07:50.660 --> 07:53.440
Let's open the web two HTML.

07:55.310 --> 07:56.000
Over here.

08:01.160 --> 08:03.140
And the same website has loaded.

08:03.140 --> 08:06.080
So now if I go to about cash in the.

08:07.740 --> 08:11.430
And if I try to find web two dot HTML.

08:13.420 --> 08:16.870
This is just a Google search which had done previously.

08:17.050 --> 08:22.150
Here you will not find specifically example.com slash web2 dot HTML.

08:22.150 --> 08:23.620
So if I search over here.

08:24.710 --> 08:25.120
I.

08:26.680 --> 08:27.670
You see it is not finding.

08:27.670 --> 08:37.090
But if I type web one dot HTML which had the cache control header, you see it is present in the cache.

08:37.300 --> 08:45.640
So this is why it is important to know that if you have some document which you don't want a client

08:45.640 --> 08:53.950
to store or even a cache server to store, then you can add a no store header to the document or to

08:53.950 --> 08:59.890
the Http response, and this will instruct the browser as well as the cache server to not store the

08:59.890 --> 09:00.640
document.

09:02.650 --> 09:08.830
Now there is the third header which I added up.

09:09.670 --> 09:13.060
Add header cache-control.

09:14.440 --> 09:17.110
Max age is equal to 200.

09:19.460 --> 09:20.990
Let's save this.

09:22.910 --> 09:24.890
And if I do a call.

09:32.170 --> 09:34.490
You see there are three headers which are added.

09:35.720 --> 09:38.180
One is max age, no store and max age.

09:38.180 --> 09:39.080
So let's see.

09:39.110 --> 09:40.610
Max Age and Max age.

09:40.940 --> 09:49.010
So if we have max, age is equal to 120 and Max is is equal to 200, then the browser will store the

09:49.430 --> 09:52.340
particular document for one 20s.

09:52.370 --> 09:59.570
However, the cache server or the public cache server will store the document for 200 seconds.

10:00.530 --> 10:10.790
Now, if the Max Age directive is not present and only the Max directive is present, then both the

10:10.790 --> 10:18.080
browser cache as well as the intermediary proxy cache will store the document for one 20s.

10:18.470 --> 10:26.990
So adding a max age allows us a lot of flexibility to determine on whether the document should be stored

10:26.990 --> 10:29.870
in the public cache or in the private cache.

10:29.870 --> 10:33.030
And if yes, then for how many seconds?

10:33.420 --> 10:41.430
So this type of flexibility was not provided in the Http 1.0 protocol where we just had the expires

10:41.430 --> 10:41.820
header.

10:43.260 --> 10:45.540
So this is it about this video.

10:45.570 --> 10:47.460
I hope this has been useful for you.

10:47.460 --> 10:49.410
And I'd like to thank you for viewing.
