DEV Community

Cover image for HTTP Caching Tech
Cielo Raymundo
Cielo Raymundo

Posted on • Updated on

HTTP Caching Tech

In this blog we will be going through what is caching, what is http caching and an overview of some http caching technologies out there for us to use.

What is Caching?

Caching reduces time and resources needed to generate a result. Caching doesn't fetch data from the source instead it builds the result once and stores it in cache, where subsequent requests can be satisfied by returning cached results. Caching objects are stored in the cache until they expire or are explicitly deleted.

HTTP Caching:

Now since we know what is caching, what exactly is “HTTP Caching” ? As you may know HTTP is a protocol used throughout the internet. Since it has been around for a while now, some extensions have been added to its specifications that allows the web infrastructure to cache HTTP responses.

All caching technologies working in the HTTP layer work as read-through caches. Read-through caches are caching components that can return cached resources or fetch the data for the client. If the request cant be satisfied from the cache the client connects to the read-through cache rather than to the origin server that generates the actual response. This is transparent to the client, since the client cant distinguish if they received a cached object or not.

When a client sends a request, it is sending that request with headers that include different methods. In these headers we are able to control caching of our web pages. Cache-Control is a header that allows you to decide how you are going to be storing the responses to your clients.

The HTTP protocol gives you a lot of flexibility on how you want to deploy caching between client and server.

HTTP Technologies:

HTTP-based caching is easy to plug into existing applications, the four main types of HTTP-caches. They include: browser cache, caching proxies, reverse proxies and CDNs.

Browser Cache:

It is one of the most common types of cache which is built into all modern web browsers. These built in caching capabilities reduces the number of requests being sent out. Before a request is sent the browser first checks the cache for a valid response, if there is a valid and fresh response then the browser will use that instead of sending the request.

Caching Proxies:

It is usually installed in a local corporate network or by an Internet Service Provider (ISP). This is a read-through cache that is used to reduce the traffic caused by users by reusing responses between those users. The larger the network is, the more they are able to save which is why it was common for ISPs to install caching proxies and route all of its traffic through them in order to cache as many requests as possible.

Reverse Proxy:

Works the same way as a regular caching proxy, but by placing a reverse proxy in your data center it reduces the load put on your web servers. By using reverse proxies you can get more flexibility since you can override HTTP headers and better control which requests are being cached and for how long.

Content Delivery Network (CDN):

A CDN is a distributed network of cache servers that work similarly to cache proxies. They depend on the same headers but are controlled by the CDN provider. By using a CDN you reduce your server's load put, save on network bandwidth, and improve the UX by pushing content closer to the user. CDNs usually have many data centers around the world which allows them to serve cached results from the closest cached server. You can implement this by creating a “static” subdomain and generating URLs for all your static files using this domain. Configure the CDN provider to accept these requests and point these URLs to the CDN provider. If a CDN fails to serve a response then it forwards the request to the original server and cache that response. You can also configure CDN providers to serve sciatica and dynamic content so that clients never connect to your data center directly.


Thank you for reading!!! :)

Top comments (1)

Collapse
 
rogbonna1 profile image
Reuben Ogbonna

This is such an informative post! I learned so much!