What is Caching?

Updated Jul 17, 2020・1 minute read Post By Dev Dojo
What is Caching?

If you've ever heard the term cache or caching, and you're not too familiar with what it means. Fear not! Keep on reading to get the simplest answer any idiot could comprehend.

Let's start things off with a quick example of caching and how it works.

A quick example

When you type in a URL in your browser somewebsite.com and press ENTER. Your computer (referred to as the client computer) makes a request to the server. The server is responsible for sending back a response which displays in your browser.

We can pretend that the server does a simple calculation:


And returns the result (response) back to you:


Now, say that someone else requests the same webpage from a different computer. The server will need to do the calculation again:


And return the response:


As you can see, every time this web page is accessed it needs to run the calculation and return the result.

Obviously, this calculation is not going to cause the server to act slow, but imagine if the calculation was large and needed to retrieve a lot of information. Well, if you were to get a large amount of traffic to that page it could make your server slow or even make it crash.

The server can save the response

What if instead of running this calculation every time, we could store the response in a temporary location perhaps a folder called 'cache', well then every time we get any kind of request, we can just return the result:


And we don't have to run the calculation.

What happens when our program or our code changes

What if our application logic changed and is now suppose to run the following functionality?


Well, if someone were to access that page, they would still get:


This is of course until we clear the cache (delete the contents of the cache folder)

After clearing our cache, our application logic will run the 5+7 functionality and store a new cache file containing the new response:


And that's the basics of cache or caching.

Need a visual representation of this example. Check out the following video: What is Caching

This was an example of server caching there are also other types of caching, but if you understand this concept all the other types of caching will work the same way.

© 2020 DevDojo LLC. All rights reserved.