Hey everyone, and welcome to the Knowledge Portal Video series.
Now, in the earlier lecture we were discussing about the Http caching and we had an overview about
it.
So continuing further today, we'll be speaking about the cache control headers in the Http protocol.
So let's get started.
Now.
In the earlier lecture we discussed about this use case where you have a cache server and cache server
has basically have the PNG file which was requested earlier by the client.
So next time when the client refreshes the page, what would happen is that the request will go to the
cache server.
Now cache server already has this MC dot png in the local cache repository, so instead of sending the
request back to the server, what it will do is it will fetch the response from the cache repository
and it will send it back to the client.
Now, there is one challenge over here is that what happens if this file, which is stored in the cache,
gets updated with a newer file?
So let's assume that this cache copy is sent to the client.
But on the backend side, this PNG file got updated on the server side.
So in that case, what really happens is that client has got a stale response or you can say client
received a older response and not the newer response.
Now there can be a lot of such cases.
Now one example I can show you is of a stock market or a share market where what you want is you do
not want anything to be cached because if you get an older response, then there can be a huge financial
losses.
So in the domain of stock markets or in banking systems, you do not want things to be cached.
So how do you do that?
How can you tell a browser or how can a web server tell a browser or a cache server to not cache the
responses at all?
And the answer is through the cache control headers.
So cache control headers are basically used to specify various directives which are used for caching
mechanisms.
So there are certain directives of cache control headers, and these directives needs to be followed
by the caching servers, be it in browser or be it a dedicated cache servers.
So these headers are used to define various caching policies with various directives provided by the
headers.
So there can be various caching policies which can be dictated by the website.
So one of the caching policies is like do not store any kind of cache at all.
So this is one caching policy.
So this can be followed by stock market or banking systems where they do not want client browsers or
any caching proxies to store any cache.
So this is one example.
Second example is store the cache, but verify with the web server whether the file is modified or not.
This is second kind.
Third example is store the cache for 24 hours.
So these are three different examples that we have looked.
So let's do one thing.
Let's go into our practical session and understand this in more detail.
Now, what I have done is I have two files over here in our lab environment.
One is no store dot PNG and one is my C dot jpg.
So let's do one thing.
Let's do a curl, I'll do a curl hyphen I on.
Let's do Dexter dot labs dot in hyphen mike dot JPG.
So now what will happen over here is that you don't really have any cache control headers.
However
if you do a no store.
Dot PNG.
Now you see there is one header called as cache control header and it says no hyphen store.
However, for earlier file there was no cache control headers.
So this cache control headers are the policies which are dictated by the web server to the caching servers.
So caching server will read this headers and then it will determine what are the policies that it should
apply for this specific file.
Now.
Again since this cache control header says no store, then the browser will actually not store this
specific file in the cache.
However, as far as my c dot jpg is concerned, since there is no caching policies which is explicitly
dictated by the web server, the browser will go ahead and store this specific file in the cache.
So we will be looking into this in great detail in the next lecture where we'll be speaking about the
no store header.
But for the time being I hope you got what the cache control headers are.
Now going back to our PowerPoint presentation, now there are various cache control headers directives
which are present.
So this is a cache control header and there are various directives to cache control headers like no
store, no cache.
They can be used in combination together, like no store, comma, no cache, comma must revalidate.
Along with that, there are other cache control headers like public private.
There are more of them and we will be discussing about these headers with practical in the upcoming
lectures to see which what each of these headers really do.
So this is it.
About this lecture.
I hope you understood what cache control headers are all about and if you have any doubts, suggestions
or questions, feel free to connect us at Twitter, Facebook or LinkedIn or mail us at instructors at
KP Labs.
Thanks for watching.