ak3nat0n
ak3nat0n

Reputation: 6288

asmx WebMethod caching on POST request in asp.net

I am using jQuery to get back some JSON data from the server. I am using a POST verb, but even after setting the WebMethod CacheDuration attribute, the JSON doesn't get cached.

I checked the response headers with firebug and the Cache-Control is still set to no-cache. How can i cache these request on the client and avoid the server to be hit every time.

UPDATE

After reading this post from scottGu I thought it would have been safe to go on to use a POST request. Does his post not apply to the kind of operation i would be trying to do ? (getting data from the server without modifying it). In fact after changing the verb to GET, i am not even getting to the web service ...

Upvotes: 1

Views: 3047

Answers (3)

Simon_Weaver
Simon_Weaver

Reputation: 146000

I've noticed differences in the way ASP.NET caches responses depending upon whether the caching parameters are query string parameters or (in my case with ASP.NET MVC) route parameters.

I never completely figured out exactly what the conditions were, but this may help someone.

Upvotes: 0

redsquare
redsquare

Reputation: 78667

You should be using a get request. Post does not cache by default. You can try to get a post to cache by using .ajax() and setting cache to true and type to post. I cannot say that this will work as typically you would not expect a post to cache. I suggest using get.

E.g

$.ajax( { url: '/bla',
          type : 'post',
          data : dataObj,
          cache : true } );

Upvotes: 3

Jesper Fyhr Knudsen
Jesper Fyhr Knudsen

Reputation: 7937

Use the GET keyword instead if you want to use caching. There is a similar question on SO.

Upvotes: 1

Related Questions