So in the last module we were discussing about the basics of the cache control header and the directives
for the newer Http 1.1 protocol.
So today we are going to talk in detail about the cache control header directives and two of the important
directives are max age and max age.
So revising our concepts on caching.
So if a browser requests for a particular document and if there is an intermediary proxy in between,
then the request first goes to the cache proxy over here.
The cache proxy will try to validate if the file is present within the proxy memory.
If it is not present, then the proxy will forward the request to the origin server where the file is
present.
Now, in response, the Origin server will send the file back to the cache server.
Cache server will store the file depending upon the cache control headers, which origin server has
sent, and it will also send the file back to the client.
Now there are two important concepts that are important to know over here.
The concepts of public and private cash.
So if we talk about this intermediary cash server, it can happen that within an organization there
is one intermediary cash server and that actually does the cashing of, say, 200 users within an organization.
So essentially this cache server is being used by multiple users, so this can be considered as public
cache.
However, we know that even browser has its own cache memory.
And that cash is private to a particular user.
And this is why it is called as private cash.
So again, revising we have two important concepts.
One is public cash and one is private cash.
So talking about the max age and max age directives within the cache control header.
We have a in the cache control max age is equal to 120.
So this 120 is basically the timeline in seconds.
So if a nginx or if a web server sends along with a document, this directive which is cache-control
max age is equal to 120.
So it basically determines that the web server is saying to the cache proxy, both public and private,
to consider this document as fresh for one 20s.
After one 20s This document will not be considered fresh and it will ask the cache to revalidate it.
Now there is a second header college s max age.
Now s max age is specifically for the intermediary cache servers.
So let's assume for a particular file there are two headers which are sent, which is Max H is equal
to 120 and S max is is equal to 200.
So what it will mean is it will mean that the public cache server should store this file for 200 seconds
before it gets stale.
However, for private cache, the file should be considered as fresh only for one 20s.
So these are directives specifically for public and private cache.
So let's go back to our links and see on how exactly it works.
So let's let me do a curl on width to show the headers for http example.com.
One dot HTML.
So here, if we see there are no cache control headers which are present, even the expired header is
not present.
So the web server specifically is not saying when the document will expire.
So during this cases, the browser will have its own heuristic method to determine the expiration time.
So let's go to the Enginex configuration.
And let's mention our first cache control header.
So I'll say add header.
So this is basically used for adding the header.
Saying cash.
Control followed by Max H is equal to 120.
So this basically means that any document that ends with Dot HTML will have a cache control header with
a directive max hyphen age is equal to one 20s.
So I'll save this and let's reload the nginx.
And if we do a curl again.
Curl.
I say example.com one dot HTML and now you have seen the cache control header with max.
Age is equal to one 20s has been added.
So let's open our favorite wireshark and let's clear this up and let's start a new packet capture.
Okay, I'll go to my chrome and I'll say Http or I'll say example.com web one dot HTML.
And this is a simple website which has been loaded.
So if I go to about cash.
And let's filter it on Web one dot HTML and let's click here and it will basically give us the.
Headers that it has received.
And here you can see cache control where Max hyphen age is one 20s.
So this basically instructs Chrome that this document is valid only for one 20s.
And after this time has expired, the Chrome should again revalidate with the server to check the freshness
of a particular document.
Okay, so now let's go back to the Nginx and let's look at.
One more directive.
So I'll comment the first one out.
And as it's very interrelated with the.
Cache-control Max age.
I'll.
At this in this video itself.
So it's no store.
So what does no store means is that do not store this particular document in cache.
So this specifies both the public as well as private cache servers do not store this document at all.
So let's see on how it works.
So I'll save the Nginx.
I'll do reload.
Let's do a curl again.
Let's open up one more document.
And here, if we see the web server is sending no stored directives along with the web two dot HTML
file.
Now.
Let's open the web two HTML.
Over here.
And the same website has loaded.
So now if I go to about cash in the.
And if I try to find web two dot HTML.
This is just a Google search which had done previously.
Here you will not find specifically example.com slash web2 dot HTML.
So if I search over here.
I.
You see it is not finding.
But if I type web one dot HTML which had the cache control header, you see it is present in the cache.
So this is why it is important to know that if you have some document which you don't want a client
to store or even a cache server to store, then you can add a no store header to the document or to
the Http response, and this will instruct the browser as well as the cache server to not store the
document.
Now there is the third header which I added up.
Add header cache-control.
Max age is equal to 200.
Let's save this.
And if I do a call.
You see there are three headers which are added.
One is max age, no store and max age.
So let's see.
Max Age and Max age.
So if we have max, age is equal to 120 and Max is is equal to 200, then the browser will store the
particular document for one 20s.
However, the cache server or the public cache server will store the document for 200 seconds.
Now, if the Max Age directive is not present and only the Max directive is present, then both the
browser cache as well as the intermediary proxy cache will store the document for one 20s.
So adding a max age allows us a lot of flexibility to determine on whether the document should be stored
in the public cache or in the private cache.
And if yes, then for how many seconds?
So this type of flexibility was not provided in the Http 1.0 protocol where we just had the expires
header.
So this is it about this video.
I hope this has been useful for you.
And I'd like to thank you for viewing.