Caching is used to improve the performance in ASP.NET MVC. Caching is a technique which stores something in memory that is being used frequently to provide better performance. In ASP.NET MVC, OutputCache attribute is used for applying Caching. OutputCheching will store the output of a Controller in memory and if any other request comes for the same, it will return it from cache result.
OutputCache attribute can have a parameter.
- [OutputCache(Duration = 60)]
- public ActionResult Index() {
- var emps = from e in db.Employees
- orderby e.ID
- select e;
- return View(emps);
- }
VaryByPara
It describes cache will be stored on the basis of a parameter. Cache will be stored on the basis of the list of semicolon separated by a string.
The example of VaryByParam is given below.
It describes cache will be stored on the basis of a parameter. Cache will be stored on the basis of the list of semicolon separated by a string.
The example of VaryByParam is given below.
https://www.c-sharpcorner.com/article/how-to-implement-caching-in-the-net-core-web-api-application/
- [OutputCache(Duration = 60, VaryByParam = "Id")]
- public ActionResult Index(int Id) {
- var emps = from e in db.Employees where e.DeptID = Id
- orderby e.ID
- select e;
- return View(emps);
No comments:
Post a Comment