Cache Aside vs Read Through Cache

What is the difference between Cache Aside vs Read Through Cache?

Retrieving data using a Cache can be done in two steps or six steps. We request data from the Cache. If data is found, the data is returned in just two steps. If data is not found, then we request the persistent storage (DB) for data, we get the data back. After getting the data from the DB, we put it back in the Cache. The entire process is about six steps. This default way of using the Cache is called Cache Aside model.

Read Through Cache can optimize the caching experience, especially when the data changes. In Read through cache, the application always requests data from the Cache. If the data is found in the Cache, then the data is returned. If data is not found in the Cache, the cache retrieves the data from the DB using an underlying provider. After retrieving the data, the Cache updates itself and returns back the data to the calling application. By using the Read through mechanism, we achieve two benefits:

  1. Data is always retrieved using the Read through Cache with a key. In Cache aside, we retrieve data using two approaches – the key approach and the DB approach.
  2. In Read through Cache, the calling application is not aware of the database layer. All calls are made to the Cache layer only. So, data is retrieved in just two steps as far as the application is concerned.

The downside to Read through Cache is the underlying provider to the database. Writing a provider plugin to the Cache is a non-trivial task.

Leave a Reply

Your email address will not be published. Required fields are marked *