简体   繁体   中英

Asp.net MVC real time application performance

i'm trying to create an asp.net mvc web application ,some pages need to show the data in "real time" ,this data is on a sql server database ,the data is changing always i created a stored procedure in sql server , i call this procedure in my controller using Entity framework linq and send the result to the browser using ajax i used outputcashing to minimize the number of execution of the stored procedure , in the same controller there is multiple methode that use the same stored procedure ,every methode execute the same procedure , how to emprove the performance of my application , is there a way to execute the stored procedure only one time for all the controller ??

this is my controller my objective is to minimize the use of the database

   [OutputCache(Duration = 20, VaryByParam = "*")]
public class JobsETLController : Controller
{

    private ETL_REP_MAUIEntities db = new ETL_REP_MAUIEntities();
    public   ObjectResult<BIOGetETLJobs_Result> ETLJobs;

    public JobsETLController()
    {


        ETLJobs =db.BIOGetETLJobs();


    }

    public ActionResult Indexp()
    {

        var y = from xx in ETLJobs
             where xx.etat!="Completed"
             orderby xx.etat ascending
                select xx;
        return PartialView(y);
}



    public ActionResult IndexpAll()
    {

        var y = from xx in ETLJobs
                    where xx.etat == "Completed"
                select xx;
        return PartialView(y);
    }

If your server is not in a web farm (multiple servers) then you can cache the data in the Asp.net Cache (this is not output cacheing, it's data cacheing). You simply set a 5 minute time limit on the expiration of the data (you say the data needs to update every 5 minutes) so that when a controller needs the data it first checks the cache, and if it's not there it will then execute the stored procedure.

MyData items;

items = (MyData)Cache["MyData"];
if(items == null)
{
   items = DoQueryToReturnItems();
   Cache.Add("MyData", items, null, DateTime.Now.AddMinutes(5), ..);
}

It's even possible to setup the cache item to be dependent upon a SqlDependency so that when the data changes, the cache can be updated.

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