1

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);
    }
3
  • There are any number of cache strategies available to you. What have you already tried so far? Commented Jun 11, 2014 at 14:26
  • i used outputcaching, but the problem is that i want the methods to share the same data result so that the query is executed only once Commented Jun 11, 2014 at 14:31
  • You have some more reading to do on the lifetime of cache strategies. The output cache is limited to a request/response stream. Commented Jun 11, 2014 at 17:25

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

it's possible to create a static object with a timer to refresh the data ?? if yes how can i do it please ??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.