10

Can I have the return value of a WebMethod outputcached? E.g. if the WebMethod has been called in the last X seconds or minutes, don't actually run the method again--just use the same result as it last served. Or should I roll my own caching internally in the class/WebMethod?

John Saunders
  • 160,644
  • 26
  • 247
  • 397

1 Answers1

16

You can use the CacheDuration parameter of the WebMethod attribute to specify that the output of the request is cached for a given amount of time.

[WebMethod(CacheDuration=60)]

The above code would make your webmethod cache its results for 60 seconds.

womp
  • 115,835
  • 26
  • 236
  • 269