A Client Cache is local to your application and lets you cache recurrently used data much closer to your application than even the clustered cache. This blog will tell you that when you should use client cache with distributed caching.
Distributed Cache provides boost to the application performance and also allows you to scale it to certain levels. Distributed cache is usually hosted in an out of process situation and in many cases it is across the network on a dedicated caching server. This means that whenever you have to get any data from cache, you have to go across the process and also across the network which travels still much faster than any other data store (but it could be still faster).
Distributed caching provides boost to the application performance and also allows you to scale it to certain levels. Distributed cache is usually hosted in an out of process situation and in many cases it is across the network on a dedicated caching server. This means that whenever you have to get any data from cache, you have to go across the process and also across the network which travels still much faster than any other data store (but it could be still faster).
Even in this situation, the client cache becomes very wide but the main issue which any client cache has to address is that whatever data is being kept in cache cannot be disconnected from distributed cache. But if the client cache becomes nothing but a standalone local cache, then you face same data integrity issues that you would have had with distributed cache.
The reason of moving the distributed cache was that you wanted data changes to be synchronized. Here client cache will maintain that consistency at the same time giving you a very fast access to your application process. NCache provides you a client caching solution where you can actually keep the client cache as “in-process cache” for your application. The data being captured in client cache is actually part of the application process. The client cache maintains the connection to distributed cache and this connection is maintained to ensure that whatever data is being kept in client cache that same data is in distributed cache.
But if another client modifies the data in the distributed cache, a notification will be sent to the client cache and the client cache will update itself. This thing with the client cache will guarantee that it is always consistent with the distributed cache. NCache hides the client cache from the application code. So your application doesn’t even know that client cache exists and you write the code as there is no client cache.
Behind the scene, NCache knows about the client cache. It looks in the client cache first for whatever item the application is requesting and if it is not there, NCache will check in the distributed cache and put it into the client cache so that it gets to the application. Technically, there can be possibility that distributed cache doesn’t have data when it is requested but it keeps on upgrading data from the disk.
During up gradation, there is a small window of time when client cache has old copy of data and the application can get the older data. But it is in very rare cases. The data in the client cache is occasionally older version of the data. But in some cases you cannot actually afford that.
NCache provides you two synchronization mechanisms. In pessimistic synchronization, every time a client checks an item, it checks in the distributed cache for the newest version. If it’s a fresher version, it takes it from distributed cache otherwise it goes to client cache and fetches it.
In optimistic synchronization, if item is found in client cache, it is fetched from there. It is much faster as it already picked from the distributed cache. In return you have a guarantee that you will never have an old copy of the data.
This is how client cache works. We use the client cache when there is a separate dedicated caching layer. Application has access to the cache across the network and application wants to fully optimize the performance. Even though distributed cache is already giving you performance boost over not having any caching but it will give you even more performance than in-proc client cache.