How to prevent the use of the .NET JSON cache

I created a simple .aspx page that queries the database for some live data, and then returns the JSONP (or finally JSONP-like) channel Content-Type application/json; charset=utf-8 Content-Type application/json; charset=utf-8

Here is the output format, more or less:

 jsonp1307643489579([ ["12345","Text Here","99999","More Text Here","True","False","7/31","1"...], ["12345","Text Here","99999","More Text There",...] ] 

Then the jQuery.getJSON call appears:

 var url = "myURL.aspx?id=123&callBack=?"; $.getJSON(url, null, function(msg) { etc etc. 

Everything works fine except for the following. In my development environment and on my local server, fresh data is returned in real time every time. But on the production web server, the data is stubbornly cached until I recycle the IIS application pool (!)

Some things I tried without success.

1 / cache: false in ajaxSetup does not work.

2 / Disable output caching in the web.config file.

2a / OutputCache Location = "None" in aspx page ads does not do this.

3 / Added random unique request data to the call .getJSON (url). Seeing how we add a unique callback parameter for each call, I assume this has already happened.

Any idea why my web server supports these cached application / JSON files?

EDIT: I look at the actual .aspx feeds when they exit the web server and they are cached there. Therefore, as I understand it, this is a web server caching problem and not necessarily a JQUERY caching problem.

+4
source share
3 answers

It turned out that the .ASPX server page actually caches the data. For anyone who focuses on client-side AJAX materials, I overlooked the obvious.

So, I added preventative measures to the server side (Response.ExpiresAbsolute, etc.), and this did the job.

0
source

Before making any getJSON calls, use the following:

 jQuery.ajaxSetup({ cache: false }); 

I fought the same problem in about half an hour yesterday. I'm not sure why manually adding a random query line did not work, but this solved the problem for me. The cached hits were completely random until I added the general setting above.

+10
source

To clarify @Stefan's answer, setting the cache to false tells jQuery to add a random query string to make the query unique.

Example: myURL.aspx? id = 123 & callBack = & _ = 13245897565132154878

+1
source

All Articles