Caching for .NET.

In the ASP.NET MVC application I'm working on, there is a lot of static data (there is no update / insertion into this table at run time) that I need to get by grouping by different columns or summing up and aggreation, the math operations are pretty simple .

Now in the repository there are many calls that slow down the reaction of the controller. Can you suggest a good caching structure that allows me to cache repository calls (with the same input parameters) without writing my own code

+6
source share
2 answers

Memorycache just suits your business by simply adding to 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, which you will be familiar with if you used the ASP.NET Cache class. The main differences between the Cache and MemoryCache classes are that the MemoryCache class has been modified to make it suitable for use by the .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 instance of AppDomain.

+5
source

Cachemanager

CacheManager is an open source caching framework for .NET written in C # and available through NuGet. It supports various cache providers and implements many advanced features.

Just 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"); 
+1
source

Source: https://habr.com/ru/post/948298/


All Articles