How Caching Helps In Improving Performance Of Application

How Caching Helps In Improving Performance Of Application


Try to remember the highlight of your last vacation. How long did it take you? Now try to remember it again. You were probably able to remember it much faster the second time. Have you ever wondered why this happens? It is because as soon as you recalled the event the first time, your brain saved this information to your recent memory.

Caching works on the exact same concept - Caching is a method of provisionally storing the contents of a webpage or an application in locations close to the user, like the way your brain saved the information to your recent memory.  

There are several types of Caching options available like database Caching, application Caching, distributed Caching, etc.

In this article, we’ll talk about how Caching helps in improving performance of the application.

What is web and application Caching?

A Google study reveals that a new visitor will stay and comeback only if the app or page loads content under 3 seconds! So, you have only 3 seconds to hook the new visitor to your site or application.

Naturally, website/application developers try out and use different techniques to optimize performance and improve speed. One such method is web Caching. In this method, the shared page elements viz, JavaScript, CSS, images, etc. are downloaded and stored closer to the user so the browser can retrieve this data from the stored location, instead of querying the web server again.

Caching can be executed at diverse levels on the network path. The following are the possible Caching units between the origin server and the browser:

  • Local browser: The browser keeps a place on your hard disk where it stores content that is being frequently requested.
  • ISPs or Caching proxies: Servers along the network path can also cache the content. These servers can either belong to ISPs or any other third party.
  • Content Delivery Network (CDN): CDNs utilize multiple networked servers to distribute the web content from various locations closer to the users.
  • Proxy for your backend server: You can have the infrastructure built on the top of your backend servers, which can cache all the content and act as a central point for dipping the load on your backend server.

The following diagram illustrates in a simplified manner.

Caching - simplified manner

In addition, Caching tries to reduce the network traffic from the internet servers. Network load can be reduced substantially as the pages that are served from the cache must travel across less of the network than when they are served by the provider of the content.  

Also, the content can be distributed globally, zonally or as per requirement to address the duplication.

Finally, Caching can reduce the number of requests on the content provider. It may also lower the transit costs for access providers.

Another way to better the speed of the application is by installing the Apache server - a reliable, secure, and fast web server. But sometimes, even Apache's out of the box speed may not be enough. Some circumstances might call for an even faster experience. One tool that helps in speeding up Apache is the Varnish Cache - an open source web application accelerator (also called a caching HTTP reverse proxy) that speeds up your web server by 10x to 300x depending on the architecture.


Data Pre-fetching

Additionally, data pre-fetching is also a beneficial possibility. Data pre-fetching is basically the fetching of web or application data in advance by a proxy server or client before any request is send by a client or proxy server.

A major advantage of using pre-fetching is that there is less traffic and a reduction in latency. When a user sends a request for a web object, instead of sending a request to the web server directly, the request can be fetched from the pre-fetched data.

Query prefetching is more focused on reducing the query result set latency time. The query that is fetched is stored in cache for next subsequent access. A very useful tool of the application is content driven or having configurations stored in database.

For example: One of our client had an online assessment portal. The portal was based on the Learning Management System, Moodle. It consisted of a wide selection of courses that are accessible to people to attend the theory classes online as well as take assessments.

Most of their users were either students or working professionals. This resulted in surge of traffic on the website in morning or evening hours. The surge was sudden which resulted in the site being stalled and crashed. Moreover, the web platform could not support more than 15 concurrent tests.

We reviewed the client’s entire set up and arrived at a simple solution - to enable the application with cache. We advised to use the memcache tool to prefetch the query and content. Static data and query were reused and the application server was freed up for assessment processes.

Caching improved the application access and user experience as 40 + users could attend the assessment and 60 + users could use the web platform at same instance.

In addition, after we measured the improvement we found that the website load time reduced and assessment videos were loading at a 50% increase in speed.

In a typical web environment, Data pre-fetching is applied at three major areas:

1) Ahead or along a web server
  • Web server to the final rendered page on the browser
  • CDN (Content distribution network)
  • Proxy web server
2) Ahead or along with processing
  • Code level cache processing for similar calls
3) Ahead or along Database
  • Database - queries for same user
  • Large query with repeated calls.

How does Caching help in improving user experience?

Among several components that unite to build a rich user experience, Caching is one of the most important aspect.  It has the following advantages:

1. Reduced latency

51% of online shoppers in the US say that a long site loading time is the top reason they’d abandon a purchase.

Therefore, the speed at which the webpage loads is crucial in ensuring a good digital experience and Caching can reduce load time as it serves content from a location nearest to the users – either on the user’s hard disk or a nearby server. Thereby, reducing the latency in the roundtrip time by recovering the content much faster.

The time taken to retrieve the resource from the cache will be lower than the time it takes from the origin server and this speeds up the content delivery process significantly.

2. Content availability

As users from across the globe access the website for information, content availability becomes a key constituent in user experience. A site may not load due to several reasons such as – frequent interruptions in the network or sporadic outages on the site. In such cases, Caching saves the day by serving end users the cached content.

3. Avoids network congestion

The internet handles huge amounts of data throughout the day and also has to manage heavy traffic; as a result, congestion in the bandwidth can be an issue on major networks.

To understand this better, let's take an example. 

Example - Imagine that there is a famous restaurant that serves the most delicious food in town, but they are based in only a single location and do not have multiple outlets. Naturally, the restaurant becomes a crowded spot catering to customers every few minutes. If the restaurant exhausts all of its resources in trying to serve every customer, it could result in a delay in the service, in turn resulting in a long line of customers waiting to be served.

The restaurant would be able to manage better if they had more than one location in the city to serve customers. This would help distribute the customers and balance the load.

The same logic applies to the Internet as well. Network congestion can be greatly reduced with Caching, as the path traveled in fetching the content is cut short when it’s cached. As all the user requests are not directed to the origin, it frees up the network and reduces the load on the origin server, helping it serve non-cached content faster.

Although implementation of Caching is a vital cog that will help grow your business positively, it is necessary to understand that tailored solutions are the way to go. There is no one-size-fits-all solution. Therefore, it is very important to ensure optimal Caching policies are in place to suit your business.

Finally, Caching may not be the talisman, but it will ensure that your business stays afloat and well-off with minimal exertions.


Vinit Sharma, a seasoned technologist with over 21 years of expertise in Open Source, cloud transformation, DevSecOps strategy, and software architecture, is a Technical Architect leading Open Source, DevOps, and Cloud Computing initiatives at Clarion. Holding certifications as an Architect and Business Analyst professional, he specializes in PHP services, including CMS Drupal and Laravel, contributing significantly to the dynamic landscape of content management and web development.

Talk To Our Experts