Home System Design Tutorial What is Web Cache and how does it speed up your website?

What is Web Cache and how does it speed up your website?

Web Cache (a.k.a HTTP Cache) is temporary storage used for storing frequently accessed static data such as HTML, CSS, images, etc to reduce the latency and the server load.

Web caching is a process of storing data for frequently accessed by users for faster to enhance web page/content delivery speed. The first time when users visit a web page, the original page is cached and in the subsequent user’s request for the same content, the cached copy is returned, hence reducing the server load. The Cache server too are updated at a specific time interval to make sure, the cached copy of web content is not stale or to make sure the freshest copy of the content is cached and returned.

Web Cache Nlogn
Web Cache Working

Types of Web Cache

Web content can be cached at various locations between the original server and the client. Web content can be cached at the client’s browsers or user agent, or a different proxy server can be used to cache static contents.

    1. Forward Cache (Browsers Cache) – Forward cache is a cache stored outside the webserver e.g. it can be stored at the client browser or at Internet Service Provides(ISP) etc. They store the heavily accessed content or reuse with low latency. The browser cache is limited to one user and it can store the private responses specific to a user.  Ex – When you press the back button on the browser, instead of re-requesting the page, the browser returns the cached copy. Another example can be if you browse twitter with poor connectivity, it will load the basic layout of twitter(cached copy), but the actual tweets will take time to appear.
    2. Reverse Cache (Caching Web-Servers) – The Reverse cache or caching proxies sits in front of one or more web servers or web apps, and caches or replicates the most visited web content on caching servers at many different locations. Since many users visit the same popular content(say any trending video), hence their hit rate is higher than Browers Cache.
      A most popular example of Reverse cache is the Content Delivery Network (CDN). CDN  is a global network that minimizes the distance between the visitor and the Website server and reduces the network latency by caching static content for a website (i.e, images, HTML pages, javascript & CSS files, and videos) and loading the static content from the geographically closer server called PoP or Point of Presence.

Web Cache Terminologies

The following are the important terminologies used in web caching.

  1. Origin Server – The origin server(a.k.a web server) is the main web server, where the actual content is stored. The content used in the caching server is retrieved from the origin server itself. Also, if a content is not found in the caching server (Cache miss) then it is fetched from the origin server.
  2. Cache Performance – Cache performance is measured in terms of Hit Ratio. Hit Ratio is a ratio of the number of requests found in the cache server to the total number of requests made. Greater the hit ratio, the better the cache performance.
  3. Freshness – The term freshness describes the content that the content present is cache is synced with that in origin server and can be used without rechecking with the origin server. Only fresh content will be used by caching the server as a response to a request.
  4. Validation – An expired (or not fresh) content is known as a stale item. Once the cache entry becomes stale, validation is done with the origin server to check whether the stale item still represents the most recent version of the content.
  5. Invalidation – Invalidation involves the removal of an item from the caching server. This is done to make sure the user does not get an old outdated copy of the content. If POST, PUT or DELETE request is made a resource specified by a URL, it means that resource at origin server has been updated and the cached copy is not stated hence the existing cached copy will be invalidated.

Benefits of Web Caching

  1. Faster delivery of web content to the user.
  2. Less Bandwidth consumption.
  3. Reduced workload on the server.
  4. Enhanced robustness of the Web services. If the remote server is not available due to a crash or some other reasons the client can still obtain a cached copy at the caching server.

Further Reading

  1. CPU Cache – The cache is the high-speed data storage memory. It is a temporary storage area that lies between the processor and the main memory(RAM) of a computer for faster data retrieval. It stores the copy of data/information frequently used. The information stored in the cache memory is the result of the previous computation of the main memory. The data stored in CPU cache need not be synchronized with the actual main memory content every time. see more…
  2. CDN –  CDN is a collection of many caching servers in multiple geographical locations each(a.k.a., points of presence, or PoPs) connected together. Each PoP contains the cached version of the website. When a user requests a webpage the, CDN algorithm redirects the request to the server which is closest to the location of the requesting user, hence decreasing the latency and optimizing the performance. see more…

Subscribe to our weekly newsletter

Join our community of 1000+ developers and stay updated with the fast moving world of computer science

We promise, we won't spam
Even we hate spam as much as you hate them


Please enter your comment!
Please enter your name here