WEBVTT

00:00.260 --> 00:02.680
Welcome to the Knowledge Portal Video series.

00:02.690 --> 00:09.920
So today we are going to talk about two of the important Http headers which are useful specifically

00:09.920 --> 00:12.740
for the Http caching is concerned.

00:14.280 --> 00:18.630
So revising the caching concept that we have already learned.

00:19.080 --> 00:24.180
So if a client sends a request, the request goes to the cache.

00:24.660 --> 00:32.130
Now, if the cache does not have a response stored, then it will forward the request to the origin

00:32.130 --> 00:32.760
server.

00:34.050 --> 00:38.040
Now the origin server will send the response back to the cache.

00:38.850 --> 00:47.040
The cash will force store the response inside its cash memory and also send it back to the user.

00:48.870 --> 00:54.880
Now the question that comes is for how long the response should be stored in the cache.

00:54.900 --> 01:01.290
Should it be stored for one hour or maybe 24 hours, maybe 48 hours or maybe even one year?

01:01.740 --> 01:03.750
So you do not know that?

01:05.230 --> 01:10.060
And just touring based on probability is not the right way either.

01:10.930 --> 01:19.090
And this is one of the reasons why Http has introduced two of the important headers which are date and

01:19.090 --> 01:19.960
expiry.

01:24.490 --> 01:35.290
Now expire headers basically defines for how long a resource should be stored in the cache memory.

01:35.950 --> 01:45.820
So expire headers can tell the cache to store the response maybe for two hours, maybe for one hour,

01:45.850 --> 01:47.950
or to not store the response at all.

01:49.390 --> 01:57.070
So if we take a look into an example, this is one of the expires header that comes along with the Http

01:57.070 --> 02:02.890
response packet and it says expires followed by the date.

02:03.130 --> 02:09.850
Now the date that it is sending is in terms of GMT and not the local date of the server.

02:12.090 --> 02:12.990
Now.

02:14.410 --> 02:16.230
Talking about the date header.

02:16.440 --> 02:24.210
The server also sends the current date of the Http response when it was sent.

02:24.690 --> 02:30.180
Again, if you notice the date is in GMT and not in local.

02:31.330 --> 02:39.190
Now let's assume that the client is receiving this header.

02:39.370 --> 02:45.430
Now, it might be possible that the date in the client system is a bit out of sync.

02:46.150 --> 02:54.160
So it might be possible that during that time the response will not be properly cached.

02:54.760 --> 03:04.430
So it is very important that the cache response should be up to date and it should not serve stale responses.

03:04.450 --> 03:11.230
So this is one of the reasons why the date and expire headers are used in conjunction.

03:12.440 --> 03:18.350
So let's assume that this is the date and this is the expire, which the.

03:19.530 --> 03:22.530
Engineers sent in the response.

03:22.680 --> 03:31.440
So if we subtract this, you see the date is same 2353 and the expires is also 2353.

03:31.860 --> 03:33.000
However.

03:33.930 --> 03:36.810
The only difference is the.

03:38.670 --> 03:41.700
D, which is 17 and which is 18.

03:41.730 --> 03:43.650
So you see the.

03:44.610 --> 03:45.040
X.

03:45.270 --> 03:49.380
So if we subtract this data, then we get 24 hours.

03:49.680 --> 03:56.680
So now the cache knows that it should store the response for 24 hours.

03:56.700 --> 04:04.260
So the response will be particularly valid for 24 hours and after 24 hours cache should contact the

04:04.260 --> 04:09.390
Origin server again to get the fresh copy of the particular resources.

04:13.340 --> 04:14.300
Now.

04:16.050 --> 04:21.690
Let's go to the Nginx server and see on how exactly it works.

04:22.970 --> 04:26.120
So let me do a call.

04:27.860 --> 04:29.600
I followed by Http.

04:31.660 --> 04:34.270
example.com slash.

04:34.540 --> 04:36.640
I have a PNG file.

04:39.000 --> 04:41.870
And let me see.

04:41.880 --> 04:44.970
And here you see there is a date header which is introduced.

04:45.480 --> 04:53.250
So date header is something that it is mandatory to send in all the responses along with the date there

04:53.250 --> 04:55.260
is a expired header also.

04:57.660 --> 05:02.010
Now if we see the current date is 18th November.

05:03.010 --> 05:06.400
1237 and expires is.

05:07.210 --> 05:09.470
20th, November 1237.

05:09.490 --> 05:17.230
So if we subtract these two header fields, then we can get that this is a 48 hour time period.

05:17.680 --> 05:25.390
So that means that the web server is saying that this particular resource logo dot PNG should be cached

05:25.390 --> 05:28.960
or should be stored in cache for 48 hours.

05:32.060 --> 05:40.100
Now there is one more header called cache control followed by max hyphen H is equal to this particular

05:40.100 --> 05:40.620
value.

05:40.640 --> 05:45.350
Now this is in seconds, which also indicates 48 hours.

05:46.400 --> 05:56.480
Now we have already seen the difference between Http 1.0 and Http 1.1, and the expires header is specifically

05:56.480 --> 05:58.310
for Http 1.0.

05:58.730 --> 06:02.570
So for Http 1.1, there is.

06:03.610 --> 06:06.730
New directive, which is cash control, which was introduced.

06:06.730 --> 06:10.630
So we'll be talking about this in more detail in the upcoming lectures.

06:10.630 --> 06:14.950
But for the compatibility we have expires header.

06:15.560 --> 06:16.400
As well.

06:18.380 --> 06:26.990
Now this expires header or you can say max age header can be different for different kind of resources.

06:27.110 --> 06:29.870
So if I say sample dot text over here.

06:33.440 --> 06:39.800
And if you see over here, the max age, the reason why I'm saying is because it becomes much more easier

06:39.800 --> 06:40.400
to read.

06:40.430 --> 06:44.060
So this is 3600 seconds, which is one hour.

06:44.850 --> 06:53.430
So if you compare this zero zero 39 and 139, then it becomes one as well.

06:53.640 --> 07:02.790
And through this, you can actually calculate or a cash server can actually calculate on how long should

07:02.790 --> 07:10.680
it consider or for how long should it store this particular response before it considers the response

07:10.680 --> 07:11.790
as old?

07:13.860 --> 07:15.270
So this is it.

07:15.270 --> 07:20.940
About this module, I just wanted to introduce the two headers which are date and expired.

07:21.420 --> 07:28.290
Again, just remember, date header is sent with all the responses and expire header is something that

07:28.290 --> 07:33.480
we can configure depending upon the resources that we want to cache.

07:35.600 --> 07:38.400
The maximum amount that r.f.c..

07:39.470 --> 07:46.130
Basically recommends that you should cash is one year, so you should not store or you should not tell

07:46.130 --> 07:50.300
the client to cash for a resource for more than one year.

07:51.300 --> 07:53.460
So this is it about this module.

07:53.490 --> 07:57.610
I hope this has been informative for you, and I'd like to thank you for viewing.
