Cashing in Memory By 6 steps🏴‍☠️

Hussein Mhadi
3 min readMay 22, 2024

--

In ASP.NET Core using .NET 8.0 , this can significantly improve 🎯the performance of your application

In ASP.NET Core using .NET 8.0 , this can significantly improve 🎯the performance of your application 🛠by reducing the time it takes to generate responses and decreasing the load on your database or other data sources ⚙.

🎯 The completed lesson provides a simplified ✨ and concise explanation of storing data in In-Memory Cache (IMemoryCache) within ASP.NET Core. This caching mechanism improves application performance by storing frequently accessed data in memory ✔. It emphasizes the importance of creating dedicated cache instances to maintain control over cache entries and sizes. By following these guidelines 🕸, developers can effectively utilize caching while optimizing application performance and stability.

Types of Caches

1 — In-Memory Cache (IMemoryCache):

-Stored in the web server’s memory.
-Suitable for apps on a single server or with sticky sessions (e.g., Azure Web apps using Application Request Routing — ARR).
-Can store any object.

2- Distributed Cache:

- Necessary for non-sticky sessions in a web farm to avoid consistency issues.
- Supports higher scale-out by offloading cache memory to an external process.
- Limited to storing byte arrays (byte[]).

In this tutorial , we will learn how to do In-Memory Caching, which stores data in the memory of the web server 💪🥇.

Warning

Using IMemoryCache with SetSize, Size, or SizeLimit can cause app failures if the cache is shared. Every cache entry must specify a size when limits are set, which isn’t always feasible in shared environments. To avoid issues, create a dedicated cache instance for your application. Always set sizes for cache entries and monitor memory usage to ensure optimal performance and stability.

more details of warning : Microsoft Aspnet Core Performance Caching

more details :

- https://learn.microsoft.com/en-us/aspnet/core/performance/caching/memory?view=aspnetcore-8.0

- https://www.youtube.com/watch?v=GkLdufOVXjI

--

--

Hussein Mhadi
Hussein Mhadi

Written by Hussein Mhadi

Software Engineer/Architect 💡 Founder programmercoffee.xyz☕ Web Developer ,Architecting Solutions,Consulting & Team Leadership 🎯 Writer and Trainer 🔥

No responses yet