CacheDuration in WebMethod ignored
I try to cache a webmethod of a webservice. By following the documentation, I h开发者_如何学Pythonave tried to add the CacheDuration
attribute, and made a test :
[WebMethod(CacheDuration = 180)]
public int TestCacheDuration()
{
return new Random().Next();
}
For each call of the webmethod, I have a different response, so it is not cached.
Is it normal ?
Thanks for your answers!
This is clearly explained in MSDN forums:
There are two issues that can affect output caching in an ASP.NET 2.0 Web service application.
In ASP.NET 2.0 the HTTP method of the test page has changed from GET to POST. However, POSTs are not normally cached. If you change the test page in an ASP.NET 2.0 Web service application to use GET, caching works properly.
In addition, HTTP indicates that a user agent (the browser or calling application) should be able to override server caching by setting the "Cache-Control" to "no-cache". ASP.NET applications, therefore, ignore cached results when they find a "no-cache" header.
and also:
Use protocols element under webSerices element in web.config:
http://msdn2.microsoft.com/en-us/library/ms228319(VS.85).aspx
source: http://social.msdn.microsoft.com/forums/en-US/asmxandxml/thread/3765f1e2-0ff5-4840-afa2-e85b3d909cd1
精彩评论