WEBVTT

00:00.260 --> 00:03.830
Hey everyone, and welcome to the Knowledge Portal Video series.

00:03.860 --> 00:11.090
Now, in the earlier lecture we were discussing about the Http caching and we had an overview about

00:11.090 --> 00:11.420
it.

00:11.420 --> 00:18.410
So continuing further today, we'll be speaking about the cache control headers in the Http protocol.

00:18.950 --> 00:21.050
So let's get started.

00:21.860 --> 00:23.030
Now.

00:24.290 --> 00:31.550
In the earlier lecture we discussed about this use case where you have a cache server and cache server

00:31.550 --> 00:38.910
has basically have the PNG file which was requested earlier by the client.

00:38.930 --> 00:47.600
So next time when the client refreshes the page, what would happen is that the request will go to the

00:47.600 --> 00:48.500
cache server.

00:48.530 --> 00:57.320
Now cache server already has this MC dot png in the local cache repository, so instead of sending the

00:57.320 --> 01:03.830
request back to the server, what it will do is it will fetch the response from the cache repository

01:03.830 --> 01:07.040
and it will send it back to the client.

01:07.780 --> 01:15.340
Now, there is one challenge over here is that what happens if this file, which is stored in the cache,

01:15.340 --> 01:18.040
gets updated with a newer file?

01:18.310 --> 01:23.530
So let's assume that this cache copy is sent to the client.

01:23.530 --> 01:30.590
But on the backend side, this PNG file got updated on the server side.

01:30.610 --> 01:37.960
So in that case, what really happens is that client has got a stale response or you can say client

01:37.960 --> 01:42.430
received a older response and not the newer response.

01:42.670 --> 01:45.800
Now there can be a lot of such cases.

01:45.820 --> 01:53.470
Now one example I can show you is of a stock market or a share market where what you want is you do

01:53.470 --> 02:01.690
not want anything to be cached because if you get an older response, then there can be a huge financial

02:01.690 --> 02:02.340
losses.

02:02.350 --> 02:10.970
So in the domain of stock markets or in banking systems, you do not want things to be cached.

02:11.240 --> 02:12.950
So how do you do that?

02:12.950 --> 02:21.140
How can you tell a browser or how can a web server tell a browser or a cache server to not cache the

02:21.140 --> 02:22.490
responses at all?

02:22.940 --> 02:26.150
And the answer is through the cache control headers.

02:26.690 --> 02:37.310
So cache control headers are basically used to specify various directives which are used for caching

02:37.310 --> 02:38.270
mechanisms.

02:38.270 --> 02:45.710
So there are certain directives of cache control headers, and these directives needs to be followed

02:45.710 --> 02:51.950
by the caching servers, be it in browser or be it a dedicated cache servers.

02:52.280 --> 02:59.510
So these headers are used to define various caching policies with various directives provided by the

02:59.510 --> 02:59.810
headers.

02:59.810 --> 03:07.150
So there can be various caching policies which can be dictated by the website.

03:07.160 --> 03:12.850
So one of the caching policies is like do not store any kind of cache at all.

03:12.860 --> 03:15.530
So this is one caching policy.

03:15.530 --> 03:23.060
So this can be followed by stock market or banking systems where they do not want client browsers or

03:23.060 --> 03:25.930
any caching proxies to store any cache.

03:25.940 --> 03:28.000
So this is one example.

03:28.010 --> 03:34.220
Second example is store the cache, but verify with the web server whether the file is modified or not.

03:34.310 --> 03:35.870
This is second kind.

03:35.900 --> 03:38.930
Third example is store the cache for 24 hours.

03:38.930 --> 03:42.560
So these are three different examples that we have looked.

03:42.800 --> 03:44.780
So let's do one thing.

03:44.780 --> 03:50.870
Let's go into our practical session and understand this in more detail.

03:51.080 --> 03:58.850
Now, what I have done is I have two files over here in our lab environment.

03:58.880 --> 04:03.440
One is no store dot PNG and one is my C dot jpg.

04:03.680 --> 04:05.690
So let's do one thing.

04:06.620 --> 04:12.500
Let's do a curl, I'll do a curl hyphen I on.

04:12.500 --> 04:19.190
Let's do Dexter dot labs dot in hyphen mike dot JPG.

04:21.680 --> 04:28.760
So now what will happen over here is that you don't really have any cache control headers.

04:29.180 --> 04:30.350
However

04:33.800 --> 04:35.510
if you do a no store.

04:38.070 --> 04:38.970
Dot PNG.

04:39.690 --> 04:47.280
Now you see there is one header called as cache control header and it says no hyphen store.

04:47.310 --> 04:51.900
However, for earlier file there was no cache control headers.

04:51.900 --> 05:01.380
So this cache control headers are the policies which are dictated by the web server to the caching servers.

05:01.800 --> 05:11.070
So caching server will read this headers and then it will determine what are the policies that it should

05:11.070 --> 05:13.920
apply for this specific file.

05:14.760 --> 05:15.780
Now.

05:16.940 --> 05:25.010
Again since this cache control header says no store, then the browser will actually not store this

05:25.010 --> 05:27.470
specific file in the cache.

05:27.620 --> 05:34.880
However, as far as my c dot jpg is concerned, since there is no caching policies which is explicitly

05:34.880 --> 05:41.690
dictated by the web server, the browser will go ahead and store this specific file in the cache.

05:41.960 --> 05:50.420
So we will be looking into this in great detail in the next lecture where we'll be speaking about the

05:50.450 --> 05:51.700
no store header.

05:51.710 --> 05:58.490
But for the time being I hope you got what the cache control headers are.

05:58.520 --> 06:06.980
Now going back to our PowerPoint presentation, now there are various cache control headers directives

06:06.980 --> 06:07.970
which are present.

06:07.970 --> 06:13.760
So this is a cache control header and there are various directives to cache control headers like no

06:13.760 --> 06:15.020
store, no cache.

06:15.050 --> 06:20.550
They can be used in combination together, like no store, comma, no cache, comma must revalidate.

06:20.970 --> 06:24.600
Along with that, there are other cache control headers like public private.

06:24.630 --> 06:31.290
There are more of them and we will be discussing about these headers with practical in the upcoming

06:31.290 --> 06:35.760
lectures to see which what each of these headers really do.

06:36.000 --> 06:37.860
So this is it.

06:37.860 --> 06:39.300
About this lecture.

06:39.300 --> 06:46.920
I hope you understood what cache control headers are all about and if you have any doubts, suggestions

06:46.920 --> 06:52.590
or questions, feel free to connect us at Twitter, Facebook or LinkedIn or mail us at instructors at

06:52.950 --> 06:53.580
KP Labs.

06:53.970 --> 06:55.200
Thanks for watching.
