What is caching and how it works?
Caching is a technique to speed up the data reading by reusing the same data. It helps to improve the performance since it doesn’t need to fetch data again from origin server.
What are the benefits of caching?
Good caching techniques support both content providers as well as to content consumers.
- Caching technique reduces network costs. Contents can be cached at many parts in networks path between the content consumer and content providing origin. So, if the content is cached as near as to the content consumer, network cost will be minimized.
- Caching technique increases the performance of the application by serving user with frequent data.
- Avoid heavy load on the origin server for the same repeated output.
- Reduces bandwidth consumption and hence reduces the network traffic.
What can be cached?
There are many types of contents in your applications. Some of them are caching friendly.
- Site logo and brand images
- Downloadable contents
- Media files etc
What should not be cached?
Any sensitive information like banking details should not be cached. Or any information which required to change frequently and user specific should not be cached.
How does caching work?
When a user requests for a content, server responds back content from origin server and saves a copy of the same content for future requests.
There are different ways caching works:
- Browser caching
- Application level caching
- Key value data caching
1. Browser Caching
Browsing caching is the most common type of caching. When ever a content consumer request for a content through a browser, a browser while sending response to consumer saves that data on user device’s hard drive. So, when consumer request for the same data in future browser just load that cached data from user’s system along with some updated data from server. It doesn’t load from the origin server. This makes the browser to load any data quickly even when the internet connection is slow.
When you load a website for the first time, it does not show the cached data. As the cached for the first time remains empty. While serving first time content to the user. Browser makes caching on user’s system of necessary files like CSS, JS, images etc. So, while loading a website for the first time might take time but once it get cached it will load the same data with higher speed.
Browser cache works until the TTL expires or user system’s hard drive is full or until the user clear the cache maually.
2. Application level caching
Application level caching involves the implementation by developers to insert some caching logic with the base code into the application. So that the processed data can be temporarily stores in memory. Hence, this level reduces the response time of content delivery by application.
Developer have to manually manage the cache. So developers must have the good knowledge of domain on which the application hosted and technology used.