DEV Community

Cover image for HTTP CACHING
Freedisch
Freedisch

Posted on

1 1 1 1 1

HTTP CACHING

So, recently I decided to take a pause with programming and learn more about caching, proxies, and load balancers. I discovered a lot of stuff that I didn't know about. Therefore, today wanted to talk a bit about HTTP caching. It's something straightforward, and some don't know how it works.

WHAT IS CACHING
For who might not know what caching is?
It's like, a memory that saves your data from a request to reduce the time of access and resources. I think it will be much clear with a picture.

Image description

As we can see, our client sends a request to the server to read a file. Our server will send back a response to the client. It can be an HTML page or a JSON file, whatever.

Let's say after sometimes you decide to reread the same file or that you want to access the same data. What happens? Is your request going to be sent again to the server? And here is where caching comes from.

The caching protocol has already saved your data temporarily. So instead of the server sending you back the response, it will be your caching protocol that does the job for the server.

Image description

Image description

As you can see, it's no more the server who is sending the response but, The caching protocol. That process augments the speed of access time and reduces the network's usage.

There are multiple ways of configuring, but I'm going to talk about one that I find more exciting talk than others: E-tag. (if you want to know more about other ways of configuring HTTP caching, check out this article)

WHAT'S ETAG?

So, Etag is a unique identifier for a request. It helps the caching protocol to recognize if that request has already been sent or not, and if yes check if he has your data in the memory.

I heard that some people don't like it because it requires more configuration when you have more than 1 server and a load balancer. But I think it's not a big deal comparing his advantage, like the fact that it helps you prevent simultaneous updates of a resource from overwriting each other.

There is a lot to say about caching😁, so I wanted to make this article simple, hope it gives the feeling to dig more and learn more about caching.😊 Here is a great ressourceif you want to learn more.

I mentioned load balancers before, but I think it can also be a great subject to discuss next time.

I hope you enjoyed reading it! 😊 Let me know what you think about caching. Have you ever used it? What was your setup?

Thanks 👌😊

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay