Welcome back to the Knowledge Portal Video series.
So in the last module we were discussing about the date and the expired header and how they help cache
to know till what time it should store a document which should be considered fresh.
However, the expired header does the basic job.
Still, it is not a very ideal solution as we consider a modern internet to have.
And this was the reason why in Http 1.1 protocol a new header called as cache control was introduced.
So revising the date and expire header again.
We have already seen it in the earlier modules.
If we subtract the both of them, we can find that here.
The timings are the same, even the month is the same.
The only difference is the day.
So if we conclude these two values, then we can find out that the document expiration can be considered
as 24 hours.
And this was a basic way for cash to know that how much time it should store a document for before revalidating
it with the origin server.
So the modern Internet has become much more complex than it was thought when the Http 1.0 protocol was
designed.
So we have already seen that.
A particular response can be cashed either by a cache server which can be at the intermediary node,
or it can also be cached on the browser side.
So all the modern browsers have their own caching mechanism where a cache response can be stored either
in the memory as well as well as in the disk.
So in the expires header, there was no way of specifying if a response should be stored in explicitly
in this.
Or explicitly in the intermediary node or in the caching node.
However, with the cache control header, a origin server can explicitly specify whether a response
should be either be stored in the intermediary proxy or it should be stored in the client side.
Cache proxy server.
So let's look into the cache control directives that it will become much more clear.
So these are the six directives which comes along with the cache control headers.
So the first one is no store.
The no store means do not store this particular response anywhere.
So by anywhere, I mean.
The intermediary proxy as well as the browser cache.
So this can be considered as anywhere.
The second directive is no cash.
So no cash basically means you can store the cash.
So the cash can be stored either at an intermediary or the browser side.
However, before sending the response.
So if the cash is stored in the intermediary proxy over here.
So if a client sends a request.
So before a cache can send the response back, it should revalidate with the origin server.
If the response is the latest one or is the fresh one.
And this is what is considered as no cash.
The third directive here is max, age zero.
So Max, age zero we have already seen corresponds to the.
Maximum age in seconds for which a document should be considered valid.
Then is the s hyphen max at zero.
Now s hyphen max is zero is explicitly for the intermediary proxy node.
This is not for the client side caching.
Then we also have the must revalidate header.
So must revalidate is somewhat similar to no cache.
We will be talking about the difference in the upcoming module.
However, if you just have an overview, must revalidate means that a cache must revalidate the document.
After it is expired.
To back to the origin server.
And there is one more header college pragma, no cache.
So this basically is used for backward compatibility.
So pragma no cache is somewhat similar to the cache control, no cache.
However, pragma no cache is specifically for the Http 1.0 based applications or browsers.
So.
Coming back to our favorite sketch.
So let me show you our nginx configuration.
So here if you see four dot PNG file we have already added expires as one hour.
So this means cache can store this particular response for one hour.
So if we do a curl.
For example.com.
Logo dot PNG.
So sorry.
It should be Http.
I'll say.
Logo dot PNG.
This is the third time making a mistake.
Slow and steady wins the race.
Okay, so this is perfect.
So here you see the Nginx is including both the expires header as well as the cache control header.
Now it's important to know that cache control header followed by max hyphen H specifies the maximum
age of a document that can be considered as fresh in terms of seconds.
The reason why expires and cache control header both are introduced by Nginx is because there can be
some browser or some application which is still following the legacy Http 1.0 based protocol and for
backward compatibility for them to understand the expires header has been introduced.
However, if both expires as well as cache control headers are introduced, the modern browser will
just read the cache control it will not consider expire header.
So this is something which is important to know.
So this is it about the basics of cache control headers and why they are introduced.
We'll be talking more about them in the upcoming lectures.
So I hope this basic information has been informative for you and I'd like to thank you for viewing.