Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure OutputCache page attribute for varying querystring values?

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?

like image 716
allan Avatar asked Dec 17 '22 02:12

allan


1 Answers

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();
}
like image 184
goenning Avatar answered Feb 02 '23 01:02

goenning