Caching

Before beginning with this lesson, I want to ask you a question. When you visit a website and request certain data from the server. How long do you wait for the response?
5 seconds, 10 seconds, 15 seconds, 30 seconds? I know, I know, I am pushing it… 45? What? Still no response…
And then you finally bounce off & visit another website for your answer. We are impatient creatures; we need our answers quick. This makes caching vital to applications to prevent users from bouncing off to other websites, all the time.

What Is Caching? #

Caching is key to the performance of any kind of application. It ensures low latency and high throughput. An application with caching will certainly do better than an application without caching, simply because it returns the response in less time as opposed to the application without a cache implemented.
Implementing caching in a web application simply means copying frequently accessed data from the database which is disk-based hardware and storing it in RAM Random Access Memory hardware.
RAM-based hardware provides faster access than the disk-based hardware. As I said earlier it ensures low latency and high throughput. Throughput means the number of network calls i.e. request-response between the client and the server within a stipulated time.
RAM-based hardware is capable of handling more requests than the disk-based hardware, on which the databases run.

Caching Dynamic Data #

With caching we can cache both the static data and the dynamic data. Dynamic data is the data which changes more often, it has an expiry time or a TTL “Time To Live”. After the TTL ends, the data is purged from the cache and the newly updated data is stored in it. This process is known as Cache Invalidation.

Caching Static Data #

Static data consists of images, font files, CSS & other similar files. This is the kind of data which doesn’t change often & can easily be cached on the client-side in the browser or their local memory. Also, on the CDNs the Content Delivery Networks.
Caching also helps applications maintain their expected behaviour during network interruptions.
In the next lesson, let’s understand how do we figure if we really need a cache in our applications?

Comments

Popular posts from this blog