In Memory Caching in .NET
<p>In the ever-evolving world of web development, one thing’s for sure: speed matters. And one nifty trick we’ve got up our sleeves to turbocharge our ASP.NET Core apps is caching.</p>
<p>In this article, we’re going to take a laid-back stroll through the fascinating world of caching, while focusing specifically on in-memory caching.</p>
<h1>What’s In Memory Caching, Anyway?</h1>
<p>Before we dive into the how-tos, let’s quickly break down in-memory caching.</p>
<p>Think of it as your app’s super-fast memory vault. It stores frequently used data right in your app’s memory, so you can grab it in a flash without hitting the database or doing complex calculations.</p>
<p>It’s like having your favorite snacks right next to you on your desk instead of running to the kitchen every time you’re hungry.</p>
<p>In ASP.NET Core, it’s one of your best friends for performance optimization, especially if you are making calls to the database to get data which remains the same for most of the time, like a list of user profiles, or some static web content maybe.<br />
For frequently changing data like stock prices, currency prices etc. it is best to go with calls to the main server or database to get fresh data instead of using a cache.</p>
<h1><strong>In Memory Caching vs. Distributed Caching</strong></h1>
<p>Now, let’s chat about the two main caching flavors: <strong>in-memory caching</strong> and <strong>distributed caching</strong>.</p>
<p><strong>In Memory Caching</strong>: This one’s like keeping your candy stash in your room. It’s super quick to access but doesn’t work well if you need to share it across multiple rooms (or servers). Example: In Memory Caching in ASP.NET Core</p>
<p><strong>Distributed Caching</strong>: Distributed caching, on the other hand, is like having a candy jar in the kitchen that everyone can access. It’s perfect when your app has multiple instances or runs on different servers. Example: RedisCache</p>
<p>Which one to choose? Well, it depends on your app’s needs and is a slightly large topic to discuss.</p>
<p><a href="https://medium.com/@ecphore/in-memory-caching-in-net-9454523a457d">Website</a></p>