I want to cache some services in my WCF Service. I used Microsoft Caching Support for WCF Web HTTP Services as my reference. My server web.config file is:
<caching>
<outputCache enableOutputCache="true" />
<outputCacheSettings>
<outputCacheProfiles>
<add name="GetCurrentDateTime" location="Server" duration="604800" varyByParam="offset; lang; categorytype" enabled="true" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
And
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
My solution is like this (containing only 2 web projects.):
And my client code is (located in Default.aspx):
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var client = new Test_Services.TestServicesClient();
var dateTime = client.GetCurrentDateTime();
Response.Write(dateTime);
}
}
Service is:
[WebGet]
[AspNetCacheProfile("GetCurrentDateTime")]
public string GetCurrentDateTime()
{
var datetime = DateTime.Now.ToString();
return datetime;
}
Simply returns current date time. So I hope it return's constant date time for "604800 seconds" interval (as declared in web.config). But it will be updated every time client call it.
I am not pretty sure but WebGetAttribute is for RESTful service. So I think the entire caching will be work only for RESTful services.
Another way for caching is described in http://pieterderycke.wordpress.com/2012/04/09/caching-in-wcf-services-part-1/.