Now, I've decided to take a break from all the hassle of web development and talk a little bit about caching, what it is and why it's helpful.
It's been pretty long since we've had an "article" on Stronia, though.
Now, what is caching? Well, here's how I learned it.
It's been pretty long since we've had an "article" on Stronia, though.
Now, what is caching? Well, here's how I learned it.
Caching refers to storing the result of a computation, so that the future request return faster.Now, if you're a person with a background in computer science you'll know what this is, but for the rest of us who don't, let me make it as simple as possible.
Caching - The intuition
Now, let's imagine, you have a phone book with about a thousand names arranged in some random order. If I ask you the phone number of let's say Alice, you'll go through your entire book and finally find the number and tell it to me. Not to mention, you'll also spend a considerable amount of time taking the book out of your pocket, opening it and then closing it and putting it back.
Then, I ask you the phone number of Bob, he's a great friend of yours and you call him pretty often. As a result, you've memorized his number. So if I ask you for Bob's phone number, you're really going to fetch it out of your brain and almost instantly tell it to me...
This is exactly what happens in computer science. If you've stored a lot of data in a database, and someone requests information, you'll have to open the db, fetch the info, close it and all sorts of stuff. Though this is much faster than you flipping your phone book, it's still not really fast given today's requirements for speed.
If you know that certain piece of information will be requested often, you should cache it, i.e. store it in memory. Hence, the request will not even have to go to the database. Reading for disk is in general slower than reading from memory, thus most caches are in-memory caches like memcached.
Okay, I get it. But how is caching like the insurance of the internet?
Caching has many forms. One of the most popular ones you- the users would have seen is called web cache.
Now let's imagine this situation. I've written this article on caching for Stronia and instead of saving my article I accidentally delete it. Not just this article but the whole website.
![]() |
Google keeps a cache of all the web pages it indexes... |
I can simple go to Google, search for the pages, download the cached version of it and put it back online. Isn't that cool? I mean, I didn't get money and I didn't pay an insurance company, but I lost my website and got it back!
So, that's pretty much my intuition, share your thoughts on this with the comments below!
No comments:
Post a Comment