MVC3 Data Caching Methods

I have a sql query (stored by proc) that takes about 8-10 seconds to return before the results are displayed in the webgrid. What is the best practice for caching efficiency in asp.net-mvc3, so the user does not need to apply this 8-10 seconds each time to load this data (less query optimization)?

+6
source share
3 answers

You can use the MemoryCache class to save the result of this query under some key. The key may be a hash of the query criteria (if you have one). And here are some guides on MSDN on how to use them.

When implementing caching, remember that this cache is stored in memory by default. This means that if you run this application in a web farm, it may be more interesting to use a distributed cache so that all nodes in the farm have the same cached data. This can be done by extending the ObjectCache class with some distributed caching solution. For example, memcached is popular and has a .NET provider . Another distributed caching is AppFabric .

+11
source

He caches this action.

[OutputCache(Duration = 300)] public ActionResult Action(){ //some operation return View() } 
+3
source

How often do your underlying data change over this stored procedure? If relatively rare, you can use a very nice function - SqlCacheDependency

http://msdn.microsoft.com/en-us/library/ms178604.aspx

Thus, your heavy SP will be called only if necessary, and the result will be cached for as long as possible.

+2
source

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


All Articles