In the ASP.NET MVC aplication that I am working on, there is a large amount of static data ( there are no update/insert to this table during runtime) which I need to retrieve by either grouping by different columns or summing up and aggreation, The mathematical operations are pretty simple.
Now there are a lot of calls issued to the repository which slows down the controller response. Can you please suggest a good caching framework which allows me to cache the repository calls (with the same input parameters) without writing custom code
In-process Cache, Persistant in-process Cache, and Distributed Cache. There are 3 types of caches: In-Memory Cache is used for when you want to implement cache in a single process.
Caching in ASP.Net is of the following three types: page output caching. page fragment caching. data caching.
Caching makes a copy of data that can be returned much faster than from the source. Apps should be written and tested to never depend on cached data. ASP.NET Core supports several different caches. The simplest cache is based on the IMemoryCache. IMemoryCache represents a cache stored in the memory of the web server.
Memorycache simply suits your case by just adding into your repositories
But remember:
The MemoryCache class is similar to the ASP.NET Cache class. The MemoryCache class has many properties and methods for accessing the cache that will be familiar to you if you have used the ASP.NET Cache class. The main differences between the Cache and MemoryCache classes are that the MemoryCache class has been changed to make it usable by .NET Framework applications that are not ASP.NET applications. For example, the MemoryCache class has no dependencies on the System.Web assembly. Another difference is that you can create multiple instances of the MemoryCache class for use in the same application and in the same AppDomain instance.
CacheManager
CacheManager is an open source caching framework for .NET written in C# and is available via NuGet. It supports various cache providers and implements many advanced features.
Simple to start with..
var cache = CacheFactory.Build<string>(
p => p.WithSystemRuntimeCacheHandle());
Easy to use...
cache.AddOrUpdate("key", "region", "value", _ => "update value");
cache.Expire("key", "region", TimeSpan.FromMinutes(1));
var val = cache.Get("key", "region");
var item = cache.GetCacheItem("key", "region");
cache.Put("key", "put value");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With