Caching is the simplest way to increase the application throughput.So what is caching ? Once the data is read from the data storage, it is kept nearby data storage. In future requests, the data are served directly from the nearby data storage. This nearby data storage is called cache. This blog introduces the local/distributed caching and different Azure Cache Services. Mainly 2 caching types of caching are there. One is local caching and second is distributed caching.
What is local caching ?
The local cache is separate for each application instance. So any changes done by other application instance won’t be visible here. Local caching is very fast. local caching is best for frequently accessed data and rarely updated data. In .NET we have a local caching mechanism called MemoryCache. Azure In-Role cache provides the local caching capability.
Local caching is best for static data or rarely changing data. But in case of transaction data the data keeps changing every minute or even second. This is where the distributed cache makes sense. In distributed caching, the cache will be common for all the application instance. All the application instances point to the same cache. So the changes in the cache will affect all the applications. We can easily scale the application by adding more servers. However, It is slower compared to local caching. Azure In-Role Cache (supports local/distributed) , Azure Managed Cache, Azure Redis Cache are the different types of distributed Azure Cache Services.
Azure Cache Services
Azure In-Role Cache
This is a cache that we can host in Azure work roles or Azure Web. We can exclusively dedicate roles to the caching or share a role with other application. As I mentioned before,Azure In-Role cache has local cache capability. The main disadvantage of Azure In-Role cache is that we have to configure and manage it.
Azure Managed Cache
Azure Managed Cache is an Azure Service. It’s consumption and storage service is same as Azure In-Role Cache . It is redundant and scalable by default. However,the Azure Redis Cache is the recommended one.
Azure Redis Cache
Azure Redis Cache is based on the popular open source Redis Cache. Redis stands for remote dictionary server.Redis is In-memory data structure store, used as database, cache and message broker. Redis focuses on performance and speed. It is key -value NoSql database. Redis has no XML support. Redis data types are strings , Lists , Sets, Sorted Sets , Hashes . In order to use the Redis cache from our application, we will have to use a Redis client such as the one from Stack Exchange. It can be downloaded as a Nuget package.