Difference Between In-Memory and Distributed Caching

Caching :- To improve the performance of any application there are many ways to improve it. Caching is one of the way by which we can improve the application performance and optimize the data retrieval from various sources. In Caching we store frequent used data into a local storage called the cache for some interval and when required we serve data from the cache so it will reduce the database operations and provides the quick data to application. It will minimize the database load and improve the response.

Image is not available

In-Memory Caching :- Data is stored into the memory of web server and it is relatively fast and simple to implement but it has some limitations of memory in server. It is suitable for using in the lightwight application and chaching is required for single instance of application.
In the above image above I have explained the In-Memory Caching technique which has below main points to remember :-

  • Data is stored temporarily into the Server Memory.
  • In-Memory Cache we can store any type of data like .Net Objects,String Data,Json Data or any other specific data.
  • It has some issues of Scalability of Memory because it completely depends on the Server Memory and it is always limited.
  • Data will be lost when application server gets restarted.
  • Implementation of In-Memory caching is very simple in terms of code.
  • It is very fast to read data from cache because it will direct access the data from Cache rather than DB Server.
  • It has faster write access.
  • It is cheaper than the distributed caching mechanism because single server memory is used for storin the data.
  • It is best suitable where you need frequenty access data on a single server and in light weight applications.

Image is not available

Distributed Caching :- As name suggests one common cache shared accross multiple servers. Sharing Cache to multiple servers will reduce the memory requirements in single hosted server and it provides the fast access of cached data and it is widely used in Microservices Architectures where application deployed on more than one server. Now a days SQL Server and Redis is the popular chioces for Distributed Caching in ASP.Net Core.
In the above image above I have explained the In-Memory Caching technique which has below main points to remember :-

  • Data is stored temporarily into the more than one Distributed Server's Memory or stored in one centralized cache.
  • Distributed Cache we can store byte array data only.
  • It is best suitable for Scalability of Memory because we can add many server as required so no memory outage this type of caching.
  • Data will not be lost when application server gets restarted because it will take the data from other servers.
  • Implementation of distibutedy caching is very complex due to distributed resources and their configuiration.
  • Read access is slightly slower because it has distributed resources and there are some network communication overhead will degarde the performance.
  • Write access is also slower due to network communication.
  • It is expensive than the in-memory caching mechanism because it required additional server and caching.
  • It is best suitable where data is shared accross multiple server and application is deployed on cloud.


Image is not available

About the Author
Sudheer Singh Chouhan is a Software Engineer having Expertise in Development Design and Architecting the applications , Project Management , Designing Large Scale Databases in SQL Server since last 17 Years.
Skill Sets :- Microsoft .NET technologies like ASP.Net Core, Web API, LINQ, Web Forms, WinForms, SQL Server, EntityFramework, Design Patterns, Solid Principles, Microservices, AWS Cloud.