Understanding write-through, write-around and write-back caching (with Python)
This post explains the three basic cache writing policies: write-through, write-around and write-back. Although caching is not a language-dependent thing, we’ll use basic Python code as a way of making the explanation and logic clearer and hopefully easier to understand. Running the Python code could also be helpful for simulating and playing around with different these caching policies.
A cache is a hardware or software component that stores data so future requests for that data can be served faster. Of course, this data is stored in a place where retrieval is faster than your actual backing store. For example, if you store a value in memory, it’ll usually be quicker to access than hitting the database and trying to read it from disk.
So, to start, let’s have two Python classes to represent our backing store and our cache. You can read from and write to each of them.
Continue reading →