简体   繁体   English

如何在ASP.NET MVC应用程序中缓存查询结果

[英]how to cache a query result in asp.net mvc application

my controller's methods uses the same query result to return various result (Jsonresult,actionresult) is there a way to cache the result in memory so that there is only one trip to data base for all controller methods so instead of executing the query the methods uses the result in cache 我的控制器的方法使用相同的查询结果来返回各种结果(Jsonresult,actionresult),是否有一种方法可以将结果缓存在内存中,以便所有控制器方法仅一次访问数据库,而不是执行方法所使用的查询缓存中的结果

the variable that i want to cache is var x = from cus in db.BIOBillPh( ) 我要缓存的变量是db.BIOBillPh()中cus的var x =

    public ActionResult BillPhp(string CodePays)
    {
        var x = from cus in db.BIOBillPh( )

                select cus;
        return PartialView(x);

    }


    public JsonResult PaysBU(string  Pays)
    {


        var x = from cus in db.BIOBillPh()
                select cus;
        return Json(x, JsonRequestBehavior.AllowGet);
    }

Controller instances are created on every call so not really. 控制器实例是在每次调用时创建的,因此并非如此。 You could create an static interim object within your controller that would have some life span before refreshing db calls. 您可以在控制器内创建一个静态临时对象,该对象在刷新数据库调用之前会具有一定的寿命。 Is this an action that's called with high frequency? 这是被频繁调用的动作吗? The marginal, if any reduction in overhead might not be worth your time. 边际成本(如果有任何减少)可能不值得您花时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM