Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How to implement Response Caching in MVC 6

$
0
0

Hi, I am trying to implement Response Caching in MVC 6 but it doesn't work. Here are two scenarioes.

Scenario 1:

Index.cshtml page:

                         <cache expires-after="@TimeSpan.FromSeconds(10)">

                                            @DateTime.Now.ToString();
                         </cache>

HomeController:


public IActionResult Index()
{
DateTime t = DateTime.Now;
return View(t);
}

at Index.cshtml and call this from Index action method then it works fine and it takes 10 ms to refresh time.

But when I tried to call this Index.cshtml view from in Index action using [ResponseCache()] it doesn't work.

[ResponseCache(Duration =10)]
public IActionResult Index()
{
DateTime t = DateTime.Now;
return View(t);
}


Viewing all articles
Browse latest Browse all 9386

Trending Articles