0

ASP.NET MVC2 page is used to show order in browser as described in How to fill document header from jqgrid data

at page load javascript retrieves correct document from browser and bind it to page elements.

document id is specifiied in query string like:

www.mysite.com/GetDocument?Id=1
www.mysite.com/GetDocument?Id=2

document is cached in browser:

[OutputCache(Location = OutputCacheLocation.Downstream, Duration = 20 * 60,VaryByParam = "*")]
public ActionResult Index(int id) 

However browser cache is not used since different page is cached for every query string. How to force borwser to cache page which does not depend on id parameter in query string ? Or is it better to pass id in post parameter ?

Community
  • 1
  • 1
Andrus
  • 26,339
  • 60
  • 204
  • 378

1 Answers1

0

You have to change the VaryByParam property.

If id is the only possible querystring key, then you can write:

[OutputCache(Location = OutputCacheLocation.Downstream, Duration = 20 * 60,VaryByParam = "none")]
public ActionResult Index(int id) 

so it will create only one cached page.

If there may be other parameters, you can define them in VaryByParam:

[OutputCache(Location = OutputCacheLocation.Downstream, Duration = 20 * 60,VaryByParam = "name;age")]
public ActionResult Index(int id) 
tpolyak
  • 1,234
  • 1
  • 9
  • 15
  • Thank you. After pressing F5 old data is still returned. It looks like this causes in server also and returns cached data if F5 is pressed in browser. How to fix ? – Andrus Oct 28 '12 at 22:01
  • @Andrus: The usage of `[OutputCache(...)]` follows to caching of data *on the server*. So it's not important what will be done on the client part (F5 for example). It will be just send request to the server and the server returns the response from the cache till the `Duration` interval will not expire. – Oleg Oct 30 '12 at 09:15
  • @Oleg: Downstream means that The output cache can be stored in any HTTP 1.1 cache-capable devices *other than the origin server* (http://msdn.microsoft.com/en-us/library/system.web.ui.outputcachelocation(v=vs.90).aspx). So its is *not cached* in server – Andrus Oct 30 '12 at 15:21
  • 1
    @Andrus: I don't know any HTTP 1.1 caching directives (see [here](http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html)) which allows to implement `VaryByParam = "name;age"` on the client side. So I think that such caching can be implemented only on the server (the web server or proxy server if any exist). You can read [here](http://support.microsoft.com/kb/811431) some additional information about the usage of Programmatic Approach instead of Declarative. – Oleg Oct 30 '12 at 15:46
  • @Oleg: thak you very much. I must probably pass document in in post buffer and remove it from query string. Hopefully browse caches it in this case. – Andrus Oct 30 '12 at 18:44
  • @Andrus: You are welcome! I'm sure that you will find the solution of the problem after some experiments. – Oleg Oct 30 '12 at 19:01
  • @Oleg. Thank you. Can you look into this issue please: http://stackoverflow.com/questions/13103544/how-to-restrict-jqgrid-textarea-height-in-grid-only This is probably very simple to you. – Andrus Oct 31 '12 at 18:18
  • @Andrus: You formulated the text of the question too unclear for people who don't have the problem. Probably you should include pictures which clear show the problem. Moreover it would be helpful if you create a demo in http://jsfiddle.net/ which demonstrate the problem. – Oleg Oct 31 '12 at 18:26
  • @Oleg: Thank you very much. I updated question in http://stackoverflow.com/questions/13103544/how-to-restrict-jqgrid-textarea-height-in-grid-only and added images – Andrus Oct 31 '12 at 21:37
  • @Andrus: I posted the answer on your question. – Oleg Nov 11 '12 at 11:48