WebMethod
This attribute is used to customize the behavior of your Web Service. This attribute holds up several properties like enable session, description, cacheduration, and bufferresponse. I discussed the enable session property in my previous article. Before proceeding with this article, you should follow my ASP.NET Web Service series from the following links,
A WebMethod contains the following major properties -

CacheDuration
We use this property, only when we want the result of a Web Service method in durations. CacheDuration is an integer property. Let’s understand it with an example -
Every time we click on the output button, the Web Service method will be processed and response will be returned from that Web Service method. Hence, even if we send same parameter, still the Web Service method will be executed and the response will be sent back.

When we send the same parameters to the Web Service method, there is no point in re-executing it, because we know that we got the same response, so it is better to cache the response of the Web Service method. Hence, if you want to cache the response of the Web Service method, all we need to do is:

If you specify cache duration as 15 then the response of this method will be cached for 15 seconds. Therefore, build your Web Service , which is MyWebService.asmx and update your Service reference. This process would regenerate the proxy class and completely update it.

Now, click output button,and the first time when we send the parameters (Amit and Mishra), the Web Service method will be reprocessed and then the result of Web Service method should be cached for 15 seconds. Now, if we leave same parameters (Amit and Mishra) and click output button once again and if we are within 15 seconds, then the Web Service will not be reprocessed. Instead, the response is stored in the cache and will be returned to the client. On the other hand, if the 15 seconds have been spent then the Web method will be reprocessed and then that response will be cached for another 15 seconds.
If you’re using different parameters, after making a request within 15 seconds, the changes will happen.











Hadshana KamalanathanPosted Jul 22, 2018, 1:28 AM
Thanks for sharing..
SubashPosted Mar 17, 2017, 12:18 AM
Thank you sir useful share
Santhakumar MunuswamyPosted Jun 25, 2016, 2:58 AM
Nice share
Vignesh ManiPosted Jun 15, 2016, 8:42 AM
Good
Thiruppathi RPosted Jun 15, 2016, 1:07 AM
Nice...
Debasis SahaPosted Jun 15, 2016, 12:45 AM
Good share..
RajaPosted Jun 15, 2016, 12:17 AM
Nice Share...