Understanding Cache
April 06, 2021
1 min

What are Cache?

Simply put cache are database on redbull. They are considerably faster in read and write times when compared to traditional SQL databases. The primary reason for cache being fast is because they are stored in faster memories (likes of RAM) and databases are based out of comparatively slower memories (likes of ROM).

Why Do we need cache?

To answer this, let us consider a scenario.

You are preparing for a flash sale on your online store. The quantity of the product is limited and so is the sale duration.

If you were to use a traditional database for this job, there is more than high chance that you end up jeopardising the entire sale. Here’s how,

Flash sales usually attract a huge volume of customers into your site and for every hit on the product page, you will have to determine whether the item is still available for purchase or not and also with every purchase the quantity should be updated almost instantly. If you are using slower database to maintain the quantity of the product, owing to slower read and write time, you might assume that the product is still in stock when it is not. This, coupled with high volume of customers trying to make a purchase, you might end up selling much more products than you actually have.

Well this is the reason why cache memories are used. To ensure that data read and writes are happening in real time regardless of the request volume. Since cache memories are based out of ultra-fast memories, they can handle the insurgence of data coming in and keep it updated. Of course, In reality architecture will be much more complex with alternative solutions as well but, this serves the purpose of explaining the need of cache memory quite well.

Speed of cache comes at a cost though, they are very expensive in comparison to traditional database and must be used very carefully. We should cache expiry judiciously to ensure no redundant data is present in the cache.

Related Posts

Understanding relation between CRUD operations and API methods
February 27, 2021
1 min
© 2021, All Rights Reserved.

Quick Links

About UsContact UsSite Map

Social Media