Caching – I
Caching – I
What is Cache?
It is the place where we store the frequently accessed data so that for future requests the data can be served faster instead of querying from the Database.
Benefits of Caching :
1. Reduces our network calls
Usually whenever the server requests for the data then the call goes to Database. And when the request for the same static data comes 100 times then it calls the Database 100 times but when the data is stored in the cache then there is no need to call the Database again and again and in this way, it reduces our network calls.
2. Improves the Performance
When we have data stored in the cache(In Memory/ SSDs) then the reading of the data is faster as compared to data stored in HDD. This improves the performance of our Application.
3. Avoid Recomputation
Cache helps to avoid the recomputation of the data. For Example: You want the average age of all the users of the application, then in this case you fetch all the users from the Database and compute the average, and you will do this process again and again when you need the average age. This will increase the cost. To save the cost and avoid the recomputation we compute once the average age and then save the average age in form of a key-value in the cache. So that we do not need to fetch all the data from the Database again and again.
4. Reduces load on Database
When we have a lot of servers and all of them are hitting the database for the information this will increase the load on the DB. But when we have 2-3 cache then the servers get the information from the cache and in this way it reduces the load from the backend.
Drawbacks of Caching :
1. Expensive Method
The hardware required for caching the data is expensive. Because the cache runs on SSDs which are expensive compared to the comparative hardware that a database runs on.
2. Stores less data
When you store tons of data in the cache then the speed of search time will increase and it leads to no use of caching.
3. Takes up storage
Caches use your device’s local storage, they can take up space that you could use for other things. If your device’s storage becomes too full, that can decrease your computer’s speed. It can also reduce the speed of your applications and web browsers. To help reduce the amount of storage your caches use, it can be helpful to clear them every once in a while to reduce their size and improve your device’s performance.
4. Stops loading updated content
Though most websites and applications have functions that force caches to download the most updated files and content, those systems don’t always work. The data your cache saves might stop websites from showing you their most updated content. If you have caches that automatically fill in your login or password information, they can also prevent you from switching accounts or manually entering information until you clear them. Once you delete the cache’s data, webpages can show you their most updated information, and all log-in windows can open anew.
In this blog, we have discussed caching, in the next one of the series we will discuss the implementation of it via different providers in Spring Boot.