By Sriram Mannava
In this article, we'll see how we can implement write-through and write-behind caching strategies using NCache step by step.
Caching is the idea of persisting a frequently read item in a nearby place to pick it up faster than to fetch it only when required. While designing an application or a system, caching is an important technique to be applied, because of the added advantage of speed and skipping unwanted wait times. When you are trying to fetch when it is actually required, you are waiting the system. It is also a way of cost optimizing, because you will reduce your storage hits and in some cases the less the storage hits the less you are charged (e.g Cloud). A cache is generally a high-speed memory which is present closest to the system that uses it.
When an item is present in the cache, we call it a "Hit" and the retrieval is faster – you’ll just pull it out of the memory and use it. If it is not present, we call it a "Miss" and you’ll need to fetch data from your storage (or from a service) and place it in the cache. This potentially reduces turn-around times for requests.
Read full ArticleGenerally applications use a Caching layer b/w their Presentation (Endpoint Layer) and Data tiers and data flows via the Caching Layer into the data. Based on how the cache is populated and maintained, we have Caching Strategies.
Like mentioned above, Caching Strategies are ways in which we populate and maintain data in the Caching layer. These approaches depend on what kind of data we are storing in the cache and the frequency in which the data is fetched or invalidated (expired or forced to update).
There are two Caching Strategies which are generally used.