简体   繁体   中英

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

the variable that i want to cache is var x = from cus in db.BIOBillPh( )

    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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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