Welcome to the Knowledge Portal Video series.
So today we are going to talk about two of the important Http headers which are useful specifically
for the Http caching is concerned.
So revising the caching concept that we have already learned.
So if a client sends a request, the request goes to the cache.
Now, if the cache does not have a response stored, then it will forward the request to the origin
server.
Now the origin server will send the response back to the cache.
The cash will force store the response inside its cash memory and also send it back to the user.
Now the question that comes is for how long the response should be stored in the cache.
Should it be stored for one hour or maybe 24 hours, maybe 48 hours or maybe even one year?
So you do not know that?
And just touring based on probability is not the right way either.
And this is one of the reasons why Http has introduced two of the important headers which are date and
expiry.
Now expire headers basically defines for how long a resource should be stored in the cache memory.
So expire headers can tell the cache to store the response maybe for two hours, maybe for one hour,
or to not store the response at all.
So if we take a look into an example, this is one of the expires header that comes along with the Http
response packet and it says expires followed by the date.
Now the date that it is sending is in terms of GMT and not the local date of the server.
Now.
Talking about the date header.
The server also sends the current date of the Http response when it was sent.
Again, if you notice the date is in GMT and not in local.
Now let's assume that the client is receiving this header.
Now, it might be possible that the date in the client system is a bit out of sync.
So it might be possible that during that time the response will not be properly cached.
So it is very important that the cache response should be up to date and it should not serve stale responses.
So this is one of the reasons why the date and expire headers are used in conjunction.
So let's assume that this is the date and this is the expire, which the.
Engineers sent in the response.
So if we subtract this, you see the date is same 2353 and the expires is also 2353.
However.
The only difference is the.
D, which is 17 and which is 18.
So you see the.
X.
So if we subtract this data, then we get 24 hours.
So now the cache knows that it should store the response for 24 hours.
So the response will be particularly valid for 24 hours and after 24 hours cache should contact the
Origin server again to get the fresh copy of the particular resources.
Now.
Let's go to the Nginx server and see on how exactly it works.
So let me do a call.
I followed by Http.
example.com slash.
I have a PNG file.
And let me see.
And here you see there is a date header which is introduced.
So date header is something that it is mandatory to send in all the responses along with the date there
is a expired header also.
Now if we see the current date is 18th November.
1237 and expires is.
20th, November 1237.
So if we subtract these two header fields, then we can get that this is a 48 hour time period.
So that means that the web server is saying that this particular resource logo dot PNG should be cached
or should be stored in cache for 48 hours.
Now there is one more header called cache control followed by max hyphen H is equal to this particular
value.
Now this is in seconds, which also indicates 48 hours.
Now we have already seen the difference between Http 1.0 and Http 1.1, and the expires header is specifically
for Http 1.0.
So for Http 1.1, there is.
New directive, which is cash control, which was introduced.
So we'll be talking about this in more detail in the upcoming lectures.
But for the compatibility we have expires header.
As well.
Now this expires header or you can say max age header can be different for different kind of resources.
So if I say sample dot text over here.
And if you see over here, the max age, the reason why I'm saying is because it becomes much more easier
to read.
So this is 3600 seconds, which is one hour.
So if you compare this zero zero 39 and 139, then it becomes one as well.
And through this, you can actually calculate or a cash server can actually calculate on how long should
it consider or for how long should it store this particular response before it considers the response
as old?
So this is it.
About this module, I just wanted to introduce the two headers which are date and expired.
Again, just remember, date header is sent with all the responses and expire header is something that
we can configure depending upon the resources that we want to cache.
The maximum amount that r.f.c..
Basically recommends that you should cash is one year, so you should not store or you should not tell
the client to cash for a resource for more than one year.
So this is it about this module.
I hope this has been informative for you, and I'd like to thank you for viewing.