WCF/WF - wcf caching - Asked By Corneliu Dinca on 23-Aug-10 10:50 AM

Does anyone have any idea how to implement caching in WCF like in the old ASMX?
All I had to do in ASMX was:
[System.Web.Services.WebMethod(CacheDuration = 1800)]
Peter Bromberg replied to Corneliu Dinca on 23-Aug-10 11:13 AM
use the WebCache attribute on your interface. An example:

[WebCache(Location = OutputCacheLocation.ServerAndClient, SqlDependency = "myDatabase:Products", VaryByParam = "categoryId")]

The above example uses a SqlDependency but it is not required.

The WebCache attribute causes WCF to integrate with the ASP.NET caching system.  It applies standard HTTP caching behavior such as the use of the cache-control and expires headers.   This is only available in the WCF REST starter kit.

You can also use ChannelFactory caching in non-REST services. See here for details:


Corneliu Dinca replied to Peter Bromberg on 23-Aug-10 11:28 AM
thanks for your response. where can I find this class, WebCacheAttribute? do i have to reference an assembly, because when I try to use this attribute, intellisense recommends me to generate a class, WebCache.
Peter Bromberg replied to Corneliu Dinca on 23-Aug-10 12:01 PM
As i mentioned, it is in the WCF REST Starter Kit.