MVC3 data caching techniques

前端 未结 3 1870
误落风尘
误落风尘 2021-02-06 11:02

I have a sql query (stored proc) that takes about 8-10seconds to return before the results are displayed in a webgrid. What is best practice for performance regarding cacheing

相关标签:
3条回答
  • 2021-02-06 11:31

    How often your underlaying data behind this stored procedure change? If relatively rarely, you can use very good feature - SqlCacheDependency

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

    This way your heavy SP will be called only when needed, and result will be cached as long as possible.

    0 讨论(0)
  • 2021-02-06 11:41

    It's caching this action.

    [OutputCache(Duration = 300)]
    public ActionResult Action(){
    
    //some operation
    
    return View()
    }
    
    0 讨论(0)
  • 2021-02-06 11:42

    You could use the MemoryCache class to store the result of this query under some key. The key could be the hash of the query criterias (if you have such). And here are some guides on MSDN on how to use it.

    When implementing caching bear in mind that this cache is stored in memory by default. This means that if you are running this application in a web farm it might be more interesting to use a distributed cache so that all nodes of the farm share the same cached data. This could be done by extending the ObjectCache class with some distributed caching solution. For example memcached is a popular one and it has .NET provider. Another distributed caching solution is AppFabric.

    0 讨论(0)
提交回复
热议问题