chrome hearts
asics

chrome hearts

chrome hearts
chrome hearts

Wednesday, January 8, 2014

How Caching Works

How Caching Works

A Simple Example: After Cache

Lets give the librarian a backpack into which he will be able to store 10 books in computer terms, the librarian now has a 10book cache. In this backpack, he will put the books the clients return to him, up to a maximum of 10. Lets use the prior example, but now with our newandimproved caching librarian.

The day starts. The backpack of the librarian is empty. Our first client arrives and asks for Moby Dick. No magic here the librarian has to go to the storeroom to get the book. He gives it to the client. Later, the client returns and gives the book back to the librarian. Instead of returning to the storeroom to return the book, the librarian puts the book in his backpack and stands there he checks first to see if the bag is full more on that later. Another client arrives and asks for Moby Dick. Before going to the storeroom, the librarian checks to see if this title is in his backpack. He finds it! All he has to do is take the book from the backpack and give it to the client. Theres no journey into the storeroom, so the client is served more efficiently.

What if the client asked for a title not in the cache the backpack? In this case, the librarian is less efficient with a cache than without one, because the librarian takes the time to look for the book in his backpack first. One of the challenges of cache design is to minimize the impact of cache searches, and modern hardware has reduced this time delay to practically zero. Even in our simple librarian example, the latency time the waiting time of searching the cache is so small compared to the time to walk back to the storeroom that it is irrelevant. The cache is small 10 books, and the time it takes to notice a miss is only a tiny fraction of the time that a journey to the storeroom takes. If it is there, its called a cache hit. With our librarian example, the smaller but faster memory type is the backpack, and the storeroom represents the larger and slower memory type. This is a onelevel cache. There might be another layer of cache consisting of a shelf that can hold 100 books behind the counter. The librarian can check the backpack, then the shelf and then the storeroom. This would be a twolevel cache.

No comments:

Post a Comment