How do I customize the OutputCache page attribute to change request values?
Assuming I have a page request that looks like
http: // localhost / accounting / products? id = 234
and sometimes it looks like this:
http: // localhost / accounting / products? id = 152
Since product items don't change often, I want each page for a specific product ID to be cached for an hour.
So for the first request the page will be cached for product id = 234 and the subsequent request for product id = 234 within an hour will be fetched from the cache. Next request after 1 hour timed out for product id = 234, new page will be fetched from server not from cache. Etc.
How should I do it?
source to share
Check out VaryByParam .
For example:
<%@ OutputCache Duration="3600" VaryByParam="id" %>
Note. The correct way to do this specifically in MVC (as opposed to web forms) is to assign an action, as Oenning demonstrated.
source to share