Why “Caching” is important?

Anurag Patel
Geek Farmer
Published in
3 min readApr 2, 2019

Caching is based on hierarchical storage of data. Caching is the act of keeping data in storage to allow retrieval without having to request the data from the original source if that data will not change frequently. From processor caching to website cache, caching is everywhere, even in you also. Everyone explains caching in terms of website caching, but caching is more than this.

A typical caching scenario is having a cached copy of a web page. That page doesn’t change every five minutes, so caching it locally on your computer saves time and bandwidth for you to re-display it if you hit reload in your browser. There are many other caches such as a database cache, or a disk cache, that speed up access for all kinds of events.

Since moving data from distant levels of the hierarchy to the CPU is expensive, it makes some sense to keep most frequently used data closer to the CPU. Doing this is caching.

While the technology and precise details of caching can be pretty complex, the underlying idea is really very simple. Let me give an example.

If I ask you what the result of 5 x 3 is, you’ll know the answer is 15. You didn’t need to calculate it, you’ve done this multiplication, so many times in your life that you no longer need to — you simply remember the result without having to do any mental processing. Well, that’s kind of how caching works.

Processor Cache

In terms of processor cache, there is always a tradeoff between access speed, capacity, and cost. Moving data from lower levels of the hierarchy to the CPU is expensive. So, it is important to keep the most frequently used data closer to the CPU. For this, in today's computer Cache Memory is used.

Cache memory is high-speed static random access memory (SRAM) in close proximity to the CPU for fast access of frequently used data. Computer microprocessor can access it more quickly than random access memory (RAM). It’s super fast, so the more of it the better as your computer doesn’t have to wait for information. The purpose of cache memory is to store program instructions and data that are used repeatedly in the operation of programs or information that the CPU is likely to need next. Fast access to the instructions increases the overall speed of the program.

Caching is an important and fundamental concept in Computer Science. Many software developers always think only that caching makes things faster. When you want to grab some data that is expensive, you cache it so that when you look up it next time, it will less expensive.

It looks easy, but it’s not

Caching includes following challenges…

  1. Dealing with dynamic data. If your data changes too quickly and you don’t want to cache it otherwise your users will get inaccurate and old data. After all, cache invalidation is one of only two hard things in computer science.
  2. Failures. What happens when your cache goes down? Can your backend systems handle the increased load? One solution is to build multiple levels of caching. For example, a local cache for each application server as well as a remote cache fleet shared between all application servers.
  3. Deployment. Local caches will likely be cleared when the web servers are re-deployed, or at least will be empty when new application servers are spun up. How do you prime the cache to avoid a spike in backend traffic each deployment? How do you deploy updates to your shared cache fleet without knocking over your backend systems when the caches get cleared?

Conclusion

Caching is a technology that increases the speed of your website without sacrificing anything in the process. When used correctly, it will not only give result in faster load times but also decrease the load on the server. We also learned about the challenges in caching. From its challenges, we can easily understand that it looks easy but it is not. Caching is extremely important because you can get dramatic performance improvements without a lot of effort in certain situations.

Thanks…

Give your important comments and follow me to read me more.

--

--