asmx WebMethod 缓存 asp.net 中的 POST 请求

发布于 2024-07-30 10:32:59 字数 507 浏览 2 评论 0原文

我正在使用 jQuery 从服务器获取一些 JSON 数据。 我使用的是 POST 动词,但即使设置 WebMethod CacheDuration 属性后,JSON 也不会被缓存。

我用 firebug 检查了响应标头,并且 Cache-Control 仍然设置为无缓存。 如何将这些请求缓存在客户端并避免每次都命中服务器。

更新

阅读此内容后post from scottGu 我认为继续使用 POST 请求是安全的。 他的帖子不适用于我想做的那种操作吗? (从服务器获取数据而不修改它)。 事实上,在将动词更改为 GET 之后,我什至没有访问网络服务......

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 ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

说谎友 2024-08-06 10:32:59

您应该使用 get 请求。 默认情况下,Post 不缓存。 您可以尝试使用 .ajax() 并将缓存设置为 true 并输入要发布的内容来将帖子缓存。 我不能说这会起作用,因为通常您不会期望帖子会被缓存。 我建议使用获取。

例如

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

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 } );
烟沫凡尘 2024-08-06 10:32:59

如果您想使用缓存,请改用 GET 关键字。 SO 上有一个类似的问题。

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

漫漫岁月 2024-08-06 10:32:59

我注意到 ASP.NET 缓存响应的方式存在差异,具体取决于缓存参数是查询字符串参数还是(在我的情况下使用 ASP.NET MVC)路由参数。

我从来没有完全弄清楚条件是什么,但这可能会对某人有所帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文