Hey everyone, and welcome to the Knowledge Portal Video series.
So today we'll be speaking about an important topic which basically rules our Internet life behind the
scenes.
And the topic name is called as caching.
Now, I'm very sure that most of you might have heard about this word.
Caching and caching proves to be a great importance as far as the Http protocol and browsing is concerned.
So let's go ahead and understand the basics about caching.
So with my favorite example that we take every time you have a client and you have a web server.
So a client basically sends a request.
So in our case it is get request on my C dot PNG and the web server responds back with the.
PNG file.
Now this is a very simple Http request and Http response.
Now the problem that arises over here is what happens if the client sends the same get request ten times
like he keeps refreshing the page.
So this get request will be sent to the server ten times and the server will have to process and send
the response ten times again.
And basically this might not seem to be a big issue, but when you talk about big websites like Facebook,
Amazon or any big websites you can consider, they have like millions of users who visit their website
every day.
And most of us, we refresh the page like, how many of you open Facebook?
Like many of you open like ten times a day, 15 times a day.
And basically what happens, like there are certain static contents like your DP picture or DP of your
friends that will not change often.
So the more you open, the more same requests will be sent to the web server and the more web server
will have to process the same response back.
So this is where the problem arises.
And in order to solve this, there needs to be a basic caching mechanism and this is something which
is implemented.
So what happens in cache mechanism is there is a middleware server, so this middleware server is responsible
for caching.
So now what happens is the client sends a request, The request.
Is forwarded to the web server with a cache in middle.
Now in the response, the web server responds back to the cache and the cache.
Sends the response back to the client.
Now let's look it in a Http way.
So the client sends a request call as get on my dot PNG.
The request is received on the cache server.
Cache server will send the same request to the web server.
Now since this is a get request on my c dot PNG, the web server will respond back with a file.
So this is the my c dot png file.
Now what cache server will do is cache server has its own storage.
So what cache server will do?
Cache server will store this file my c dot png within this storage and then it will reply back to the
client with the file.
Okay, so.
Now, what would happen is if the client decides to refresh the page, then what would happen is or
if there are multiple same requests.
Now, we already know that the cache server has stored the MC dot PNG file.
In that case, if the user decides to refresh the page, you have, you have get on MC dot PNG.
So user is sending the same request again.
So now what cache server will do?
Cache server knows that there is already a file called as MC dot PNG within its local store.
So the.
Castro will respond with the same file.
So in this case, what happened was the cache server did not send the request to the client or to the
web server.
It responded back with the local cache.
Now, this specific local cache can be a hard disk drive or it can be a memory also to fasten the things
up.
So let's look into how that would work.
Now this local cache can be a dedicated server, which an organization can have, or it can be a software
based appliance also.
So most of the browsers does have local cache.
So this is mostly a software appliance as far as the browsers are concerned.
So let's look into how that would work.
So I have a Firefox browser.
So if you go into about colon cache, this will basically tell you all the caching related information
which the browser keeps.
So you can consider this as a software appliance of the browser.
Now there are two important things to remember is.
That the cash can be stored in memory and the cash can be stored in disk.
Now, if you store it in memory, then definitely the it will be much more faster.
However.
Bisque is also quite fast, but not as fast as memory.
But overall, retrieving files from disk is much, much more faster than actually contacting the web
server and fetching the files.
Now, if you look into the disk, it basically tells you how many entries are part of the cache.
It also tells you about the storage and the storage location where the cache is stored.
So now if you go to list cache entries over here, it will basically tells you what are the files which
are being cached over here.
Now, along with that it tells you about let's show it talks about the fetch count basically tells on
how many times the item has been fetched.
It talks about the expiry time of that specific cache value.
So if you look into this specific entry, so this is something related to a PNG file.
Stars dot PNG, which is a 1 to 73 bytes.
It has been fetched two times in total.
And for how many time?
How much time it will be cached.
So it has the first retrieval time was 2410, 2017 and it has been actually cached for a good amount
of time.
You see.
11 one 2027 That is actually an amazing caching amount of time.
So generally files are cached for like one year, but this seems to be quite good enough anyways.
So let's do one thing.
What we'll be doing is let's open a file.
So Dexter Labs dot in, slash my c dot jpg.
So this is basically a image file which is retrieved from Dexter Labs dot slash my C.
So now if I keep refreshing the page question is should a browser send a request to the web server every
time and expect a response that would be much more slower?
So in this case, what the browser will do, a browser will basically.
Cached image file.
So now what would happen is if you look here, the fetch count is 13.
So this basically means that.
This file is already cached and it has been fetched for 13 times in total.
It talks about the last modified time and it talks about the expires time.
Like when will this file expire from cache?
So next time, even when you refresh the page, the chances are that it will be retrieved from the browser
cache and the get request will not be sent to the server directly.
So this is it about the high level overview about what the caching is all about in Http protocol.
Now, definitely one last thing that caching does bring.
If you note it does bring a good amount of benefits.
Now one of the very good benefits is that it reduces the overhead of the server resources.
Now, since the browser is retrieving the file from the cache, the server, the web server does not
have to process the response and send it back to the client.
So it basically reduces the overall overhead.
Second is, it decreases the network bandwidth.
Now every time a user refreshes the page and if the request is sent to the web server, then the overall
network bandwidth will be tremendously high.
And since now a browser retrieves it from the local cache, the network is not congested and third pages
are loaded much more faster since the entries are cached within the.
Desktop or within the server itself.
So these are some of the benefits of caching.
In the upcoming lectures, we will be speaking in great detail related to caching and caching related
headers.
So this is it about this lecture.
If you have any doubts suggestions, feel free to connect us at Twitter, Facebook or LinkedIn or mail
us at instructors at KP Labs.
Thanks for watching.