Home » Software Development » HTTP Caching explained

About Anirudh Bhatnagar

Anirudh Bhatnagar
Anirudh is a Java programmer with extensive experience in building Java/J2EE applications. He has always been fascinated by the new technologies and emerging trends in software development. He has been involved in propagating these changes and new technologies in his projects. He is an avid blogger and agile enthusiast who believes in writing clean and well tested code.

HTTP Caching explained

We all have noticed that opening of a webpage for the first time takes some time, but the second or third time it loads faster. This happens because whenever we visit a webpage for the first time, our browser caches the content and need not have to make a call over the network to render it. This caching ability of the browser saves a lot of network bandwidth and helps in cutting down the server load.

1.) Browser or local Caches: This is the local in-memory cache of a browser. This is the fastest cache available. Whenever we hit a webpage a local copy is stored in browser and then second time it uses this local copy instead of making a real request over the network.
2.) Proxy Caches : These are pseudo web servers that work as middlemen between browsers and websites. These servers cache the static content and serve its clients so the client does not have to go to server for these resources.

The difference between local and proxy cache is that the former can’t serve more than one agent, so 2 identical requests from 2 consumers behind the same network effectively hit the origin server twice: again, needless to say, proxy caches serve cached responses slower than local ones.

Content Delivery Networks (CDN) are of similar concept wherein they provide proxy caches from their servers , which helps in faster serving the content and sharing the load of servers.

3.)Gateway Caches : A gateway cache is a cache served by a proxy installed on the server side, called reverse proxy.

It’s different from the proxy cache, in which the proxy stands into the client side: the advantage of implementing a gateway cache is that you can share the cache generated by a client with any other client of the planet doing the same request.


Inconsistency and invalidation: When we are dealing with cache we need to make sure that the stale data is invalidated and it should be consistent. So lets see what all mechanisms are provided by HTTP which can help us make effective use of HTTP caching.

HTTP Headers

Before HTTP1.1 the only way to control caching behaviour was with the help of “expries” header. In this an expiry date can be specified. But, later more powerful and extensive heades were introduced in HTTP1.1, this was “cache-control” header. This along with “etag” gave the real power to the applications to control the behaviour of caches.

JAX-RS supports these and provides APIs to use them. In the next blog we will see how to use JAX-RS to control the behaviour of caching in order to make best use out of it.

Reference: HTTP Caching explained from our JCG partner Anirudh Bhatnagar at the anirudh bhatnagar blog.
(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Leave a Reply


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Notify of