Use Caching to Improve the Performance of your Web App
When it comes to web applications, there's no such thing as "too fast". If a website takes more than 3 seconds to load, over 50% of visitors will abandon it.
There are many ways to improve a web app's performance. One of the best ones is caching.
How Web Apps Work
Web Applications are backed by a Database. They have a simple -yet "slow"- process to create information:
- Taking a request from the user
- Processing the request
- Fetching information from the database
- Processing the information
- Rendering the output into HTML
- Sending the output back to the user
This process can be very time-consuming, especially if there is no need to go through it.
How Caching Works
Caching means saving the HTML output of the last request. Whenever a user has the same request, that's the output that will be sent back. There's no need of going through the whole process - and having to fetch the information from the database.
Of course, there’s more to it, but that’s enough to understand why caching is so important.
An Analogy to Understand Caching
I once heard a great analogy that explains caching perfectly. Imagine a taxi driver that moved to a new city and doesn't know the streets. At first, whenever he takes a customer to a certain place, he'll ask the best routes and check the GPS.
After some time, he'll remember the routes. And when he gets a request that he had received before, he won't have to repeat the process. No need to ask directions or look at the GPS. He'll know his way.
It may not be that client's preferred route, or there may be some changes in traffic that he didn't know about. But the trip will be faster because he didn't need to fetch information from his database.
Caching is a great way to improve the performance of web apps.
The process won't be personalized for every user, but the output will be sent much faster.