Assuming I have a page request which goes like
http://localhost/accounting/products?id=234
and sometimes it goes like:
http://localhost/accounting/products?id=152
Since product items does not change frequently, I want each pages for a particular product ID to be cached for an hour.
So for the first request the page will be cached for product id = 234 and succeeding request for the product id =234 within an hour, will be retrieved from the cache. The next request after 1 hour has elapsed for product id =234, a new page will be retrieved from the server not from the cache. And so on.
How do I go about this?
Ofer Zelig's answer is right, but as you are using MVC, the correct location to add the OutputCache configuration is in the action.
[OutputCache(Duration=3600, VaryByParam="id")]
public ActionResult Products(int id)
{
//
return View();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With